Skip to content

fix(sandbox): pass VSCODE_CWD env var to preserve workspace CWD in sandbox#315538

Open
yehsuf wants to merge 5 commits into
microsoft:mainfrom
yehsuf:fix/sandbox-cwd-env
Open

fix(sandbox): pass VSCODE_CWD env var to preserve workspace CWD in sandbox#315538
yehsuf wants to merge 5 commits into
microsoft:mainfrom
yehsuf:fix/sandbox-cwd-env

Conversation

@yehsuf
Copy link
Copy Markdown

@yehsuf yehsuf commented May 10, 2026

Fixes #313938

When the sandbox wraps a terminal command on Linux, it cd's into tempDir before launching the sandbox runtime. bootstrap-node.ts then sets VSCODE_CWD=process.cwd() (the tempDir) if the env var is unset, causing all sandboxed commands to run in tempDir instead of the workspace root.

Fix: pass VSCODE_CWD= as an environment variable in the sandbox runtime command, so bootstrap-node.ts preserves the correct working directory.

Copilot AI review requested due to automatic review settings May 10, 2026 13:30
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes sandboxed terminal commands using the wrong working directory by ensuring the sandbox runtime preserves the original workspace CWD via VSCODE_CWD, rather than letting bootstrap-node.ts default it to the sandbox temp directory.

Changes:

  • Pass VSCODE_CWD=<actual cwd> as an environment variable when launching the sandbox runtime.
  • Keep existing Linux behavior of launching the sandbox runtime from the temp dir while restoring the original CWD for the user command.

…ndbox

When the sandbox wraps a terminal command on Linux, it cd's into tempDir
before launching the sandbox runtime. bootstrap-node.ts then sets
VSCODE_CWD=process.cwd() (the tempDir) if the env var is unset, causing
all sandboxed commands to run in tempDir instead of the workspace root.

Fix: pass VSCODE_CWD=<actual cwd> as an environment variable in the
sandbox runtime command, so bootstrap-node.ts preserves the correct
working directory.

Includes unit test verifying VSCODE_CWD presence/absence based on cwd.

Fixes microsoft#313938
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[chat agent sandbox] Agent process CWD is set to a temp directory instead of the workspace root

3 participants