Skip to content

Fix terminal sandbox tmp dir scoping#303770

Merged
dileepyavan merged 1 commit intomicrosoft:mainfrom
dileepyavan:DileepY/srt_issue
Mar 21, 2026
Merged

Fix terminal sandbox tmp dir scoping#303770
dileepyavan merged 1 commit intomicrosoft:mainfrom
dileepyavan:DileepY/srt_issue

Conversation

@dileepyavan
Copy link
Member

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

  • derive a per-window sandbox temp folder name from environmentService.window?.id
  • create sandbox temp paths under the existing tmp root using tmp_vscode_<windowId>
  • keep cleanup targeted to this._tempDir, which now resolves to a window-specific directory
  • preserve the existing shared root location under the product data folder for both remote and native environments
  • update TerminalSandboxService tests to inject a window id and assert the scoped temp directory path
  • keep the sandbox command wrapper using this._execPath directly when launching the sandbox runtime, and return the wrapped command as-is for remote environments

Why

Previously, sandbox temp data was stored in a shared tmp directory. 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-native
  • node ./test/unit/browser/index.js --run src/vs/workbench/contrib/terminalContrib/chatAgentTools/test/browser/terminalSandboxService.test.ts --browser chromium
  • node --experimental-strip-types build/hygiene.ts src/vs/workbench/contrib/terminalContrib/chatAgentTools/test/browser/terminalSandboxService.test.ts

Fixes #299224

Copilot AI review requested due to automatic review settings March 21, 2026 19:16
@vs-code-engineering vs-code-engineering bot added this to the 1.113.0 milestone Mar 21, 2026
@dileepyavan dileepyavan enabled auto-merge (squash) March 21, 2026 19:17
Copy link
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 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?.id and create temp paths under .../tmp/tmp_vscode_<windowId>.
  • Adjust the sandbox command wrapper to invoke the sandbox runtime via this._execPath directly (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 (undefined when window.id is missing), but the tests only cover the case where a window id is present. Please add a unit test that omits window/window.id from 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;
	}

@dileepyavan dileepyavan merged commit ae0f754 into microsoft:main Mar 21, 2026
32 of 33 checks passed
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.

When running sandbox, Copilot cannot access tmp

3 participants