Fix terminal sandbox tmp dir scoping#303770
Merged
dileepyavan merged 1 commit intomicrosoft:mainfrom Mar 21, 2026
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR scopes TerminalSandboxService temporary sandbox data to a per-window subdirectory so that shutdown cleanup only removes sandbox files created by the current VS Code window, avoiding cross-window interference.
Changes:
- Derive a window-scoped sandbox temp directory name from
environmentService.window?.idand create temp paths under.../tmp/tmp_vscode_<windowId>. - Adjust the sandbox command wrapper to invoke the sandbox runtime via
this._execPathdirectly (and avoid extra wrapping in remote environments). - Update unit tests to inject a window id and assert the new scoped temp directory path.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| src/vs/workbench/contrib/terminalContrib/chatAgentTools/common/terminalSandboxService.ts | Adds window-scoped temp dir path logic and updates sandbox command wrapping behavior. |
| src/vs/workbench/contrib/terminalContrib/chatAgentTools/test/browser/terminalSandboxService.test.ts | Updates tests to provide a window id and validate the new window-scoped temp dir path. |
Comments suppressed due to low confidence (1)
src/vs/workbench/contrib/terminalContrib/chatAgentTools/common/terminalSandboxService.ts:280
- New window-scoped temp dir logic has an important fallback branch (
undefinedwhenwindow.idis missing), but the tests only cover the case where a window id is present. Please add a unit test that omitswindow/window.idfrom the environment stub and asserts the expected fallback behavior (and/or the new per-instance scoping if you change it), so regressions in non-native/browser environments are caught.
private _getSandboxWindowTempDirName(): string | undefined {
const workbenchEnv = this._environmentService as IEnvironmentService & { window?: { id?: number } };
const windowId = workbenchEnv.window?.id;
return typeof windowId === 'number' ? `tmp_vscode_${windowId}` : undefined;
}
src/vs/workbench/contrib/terminalContrib/chatAgentTools/common/terminalSandboxService.ts
Show resolved
Hide resolved
src/vs/workbench/contrib/terminalContrib/chatAgentTools/common/terminalSandboxService.ts
Show resolved
Hide resolved
alexdima
approved these changes
Mar 21, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This change scopes terminal sandbox temporary data to a per-window subdirectory so shutdown cleanup only removes the sandbox files created by the current VS Code window.
What Changed
environmentService.window?.idtmproot usingtmp_vscode_<windowId>this._tempDir, which now resolves to a window-specific directoryTerminalSandboxServicetests to inject a window id and assert the scoped temp directory paththis._execPathdirectly when launching the sandbox runtime, and return the wrapped command as-is for remote environmentsWhy
Previously, sandbox temp data was stored in a shared
tmpdirectory. Because shutdown deletes the resolved sandbox temp directory recursively, closing one window could remove sandbox files that belonged to another open VS Code window. Scoping the temp directory by window id avoids that cross-window cleanup behavior.Testing
npm run compile-check-ts-nativenode ./test/unit/browser/index.js --run src/vs/workbench/contrib/terminalContrib/chatAgentTools/test/browser/terminalSandboxService.test.ts --browser chromiumnode --experimental-strip-types build/hygiene.ts src/vs/workbench/contrib/terminalContrib/chatAgentTools/test/browser/terminalSandboxService.test.tsFixes #299224