Skip to content

Agent ran rsync -a --delete <dir>/ / in WSL (empty variable after quoting failure) and irrecoverably wiped a user drive #5541

Backlog

Description

@steotto

Describe the bug

While working on an unrelated task (preparing an upstream PR), the agent wanted to run Go tests in WSL. It passed a multi-line bash script inline from PowerShell:

wsl -d Ubuntu-24.04 -- bash -lc $s   # $s = multi-line here-string

The line breaks/quoting were mangled on the way through PowerShell -> wsl.exe, so the line D=~/src/rs-pr never took effect and $D was empty. The next line therefore ran as:

rsync -a --delete --exclude .git /mnt/c/Users/<user>/Code/<repo>/ /

i.e. "make / look like the repo, delete everything else". It ran ~7 minutes as the normal WSL user before the agent noticed (the tool output was 34 MB of rsync errors) and stopped it.

Damage: all user-deletable files on the Windows data drive D: (mounted at /mnt/d) were deleted, ~10 GB incl. a Thunderbird profile (mail) and games. D: is an SSD, so TRIM made the data unrecoverable (verified by raw MFT/cluster analysis: deleted files' clusters now return random data). C: survived only because rsync deletes in reverse alphabetical order and hit C:\Windows (permission denied) before C:\Users. The user had no backup of D:.

Affected version

  • Copilot SDK-based agent in VS Code 1.147.0 (8a14f0cc1b08d531eb83255ea3764ae22aa932b5, x64)
  • Model: claude-opus-5.5, reasoning effort medium (verified from session usage log)
  • OS: Windows 11 (NT 10.0.26300) + WSL Ubuntu 24.04
  • Date: 2026-11-20

Steps to reproduce the behavior

  1. Agent session on Windows with PowerShell tool and WSL installed (Windows drives auto-mounted under /mnt).
  2. Agent builds a multi-line bash script in a PowerShell here-string that sets a variable and then uses it as a destructive target, e.g.
    D=~/src/x; mkdir -p $D; rsync -a --delete src/ $D/
  3. Agent runs it via wsl -- bash -lc $script.
  4. Quoting breaks, the assignment is lost, $D is empty -> rsync --delete src/ / runs and deletes user files on all mounted drives.

Expected behavior

  • The agent must never run a command with --delete, rm -rf, find -delete etc. whose target is built from a variable without guarding it (set -euo pipefail, ${D:?}) and without checking the resolved path is not / or a mount root.
  • Destructive commands outside the workspace should require explicit user confirmation; none was requested.
  • Multi-line scripts for WSL should be written to a file and executed, not passed through PowerShell -> wsl.exe argument quoting.
  • When the first output shows clear signs of a broken command (bash "not a valid identifier" errors, rsync touching /mnt/c/Windows), the run should be aborted immediately.

Additional context

  • The agent's initial_wait was 400 s, so the destructive command ran unobserved for that long.
  • Root filesystem / and /mnt/c/Windows were protected only by permissions; any drive where the user has delete rights (/mnt/d) was wiped.
  • Filed by the affected user, with the summary written by the agent itself at the user's request.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    triage:needs-humanAuto-triage could not classify this issue confidently. Remove the label to re-queue it.

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions