Skip to content

[CRITICAL - Data Loss] Copilot agent bypasses WSL sandbox and deletes user home directory due to Windows/WSL quoting failure #316120

@vitmantug

Description

@vitmantug

Description

The Copilot agent caused catastrophic data loss (completely wiping the real WSL /home/user directory) while attempting to run what it thought was a safely sandboxed command.

The issue stems from a fatal interaction between how the Agent structures inline bash commands and how Windows/PowerShell passes arguments to wsl.exe. When the agent attempts to isolate destructive commands (like rm -rf "$HOME") using an inline string, the quoting fails during the transit between the Windows host and the WSL guest.

Steps to Reproduce

  1. On a Windows 11 host with VS Code and WSL 2 enabled.
  2. Engage the Copilot agent in a task that involves temporary WSL operations.
  3. The agent attempts to sandbox a command using the following pattern:
    wsl bash -lc 'set -euo pipefail; export HOME=/tmp/repro_env; rm -rf "$HOME/test_dir"; mkdir -p "$HOME/test_dir2"'
  4. The Failure: Observe that even though $HOME is exported to /tmp/repro_env in the same line, the rm -rf command targets the user's actual home directory (/home/username/test_dir).

Technical Analysis

The vulnerability is a Sandbox Escape via Quoting Corruption.

When a command wrapped in single quotes ('...') is passed from a Windows shell (like PowerShell or the VS Code terminal runner) to a native executable (wsl.exe), the Windows execution context often strips the outer single quotes and attempts to re-wrap arguments in double quotes for the CreateProcess Win32 API.

This process fails to escape internal double quotes (like those in "$HOME"). Consequently, the bash shell inside WSL receives a fragmented string where $HOME is evaluated against the pre-existing environment (the real home) before the inline export command can take effect or isolate the scope.

Impact

  • Data Loss: Irreversible deletion of files in the WSL home directory.
  • Security Risk: Deletion of sensitive configurations, SSH keys, and uncommitted source code.

Environment

  • Copilot Chat Extension Version: 0.47.1
  • VS Code Version: 1.119.1
  • OS Version: Windows 11 (Build 10.0.26200.0)
  • Feature: agent
  • Selected model: GPT-5.4

Suggested Mitigation / Guardrail

Agents must be strictly prohibited from using inline shell execution (wsl bash -lc '...') for complex or destructive strings across the Windows-WSL boundary.
Safe Pattern: The agent should write the payload to a temporary .sh file on the Windows host and execute it via:

wsl bash /mnt/c/path/to/temp_script.sh

Metadata

Metadata

Assignees

Labels

chat-ext-issueTriaging assistance tag. Automatically applied if an issue comes from the chat oss repo.info-neededIssue requires more information from posternew releaseIssues found in a recent release of VS Code

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions