Skip to content

agentHost: grant sandbox read access to application contents - #348433

Merged
Dileep Yavanmandha (dileepyavan) merged 4 commits into
microsoft:mainfrom
dileepyavan:DileepY/canvas-sandboxing
Nov 16, 2026
Merged

Dileep Yavanmandha (dileepyavan) merged 4 commits into
microsoft:mainfrom
dileepyavan:DileepY/canvas-sandboxing

Conversation

@dileepyavan

@dileepyavan Dileep Yavanmandha (dileepyavan) commented Nov 15, 2026 •

Copy link
Copy Markdown
Member

Fixes #346105.

Summary

Sandboxed canvases need read access to VS Code's application contents, not only its JavaScript application directory. Manually granting the macOS application's Contents directory allows the canvas to work with sandboxing enabled.

  • Add a memoized INativeEnvironmentService.appBundleRoot getter derived from the running host's appRoot and product configuration.
  • Resolve application read paths asynchronously and use them in both Copilot SDK and custom-terminal sandbox defaults, preserving explicit denies and managed read-only restrictions.
  • On packaged Windows/Linux installations, grant appRoot and individual regular runtime files instead of recursively granting the installation directory. This keeps sibling portable data/user-data, other sessions' databases, and portable extensions outside the application grant.
  • Supply explicit terminal runtime read paths so the terminal sandbox does not reintroduce an installation-wide grant through the executable's parent directory.
  • Keep source/non-packaged layouts at appRoot instead of granting an arbitrary ancestor.
  • Cover path derivation, portable layouts (including versioned Windows), SDK create/resume, terminal file-access checks, and policy composition in focused tests. Update affected launcher and shell-tool environment fixtures.
Platform/layout Default application read paths
macOS <application>.app/Contents
Windows <installation>\resources\app and individual regular files directly inside <installation>
Windows with versioned updates <installation>\<version>\resources\app and individual regular files directly inside <installation> and the active <version> directory
Linux <installation>/resources/app and individual regular files directly inside <installation>

Windows/Linux installation directories themselves are not recursively granted. No new user setting, write permission, or network permission is introduced.

Validation

Validation already completed for the current head; reused for this description/review-thread update because no code changed:

  • corepack pnpm run build-fast --client-only — passed.
  • corepack pnpm run typecheck-client — passed.
  • npm run -s precommit — passed through the normal commit hook, including oxlint and hygiene checks.
  • Focused local unit tests — 127 passed, 11 POSIX-only tests skipped on Windows:
$env:VSCODE_SKIP_PRELAUNCH='1'; & $env:ComSpec /d /c 'scripts\test.bat --run src\vs\platform\agentHost\test\node\copilotShellTools.test.ts --run src\vs\platform\agentHost\test\node\sandboxConfigForSdk.test.ts --run src\vs\platform\sandbox\test\common\terminalSandboxEngine.test.ts --reporter dot'

Code OSS CI for the current head passed, including Compile & Hygiene, both Linux Electron-Unit jobs (node and electron), and PR Gate. This supplies Linux verification for the shell-tool cases skipped locally on Windows.

The new getter and generated read-only policy were also checked against a versioned Windows Insiders installation. The manually tested macOS permission is documented in #346105 (comment). End-to-end canvas launches with the new default have not been verified across macOS, Windows, and Linux.

Manual verification

  1. Run the changed build and enable sandboxing in a Copilot Agent Host chat without manually adding the application directory to read-only paths.
  2. Open a plugin canvas and verify that it opens while sandboxing remains enabled.
  3. Repeat with a resumed chat and on each desktop OS, including a versioned Windows installation.
  4. On portable Windows/Linux installations, inspect the generated application read grants and confirm they do not include the portable data directory or recursively grant its installation-directory ancestor.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

The recursive sandbox grant includes portable Windows/Linux user-data directories, allowing sandboxed processes to read profile storage and other sessions’ databases.

1 open issue
What changed in this PR

This PR addresses #346105 by adding application-content read roots to Agent Host sandboxes so plugin canvases can load VS Code resources without disabling sandboxing.

Changes:

  • Adds a memoized, platform-aware appBundleRoot, including versioned Windows layouts and non-packaged fallbacks.
  • Passes the root to Copilot SDK and custom-terminal sandbox read grants.
  • Adds path-derivation, create/resume, and policy-composition coverage, plus documentation.
File Description
src/​vs/​platform/​environment/​test/​node/​environmentService.test.ts Tests packaged layouts and fallback paths.
src/​vs/​platform/​environment/​common/​environmentService.ts Derives and memoizes the application bundle root.
src/​vs/​platform/​environment/​common/​environment.ts Adds appBundleRoot to the native environment interface.
src/​vs/​platform/​agentHost/​test/​node/​sandboxConfigForSdk.test.ts Tests application contents among shared read roots.
src/​vs/​platform/​agentHost/​test/​node/​copilotAgentSession.test.ts Covers application grants during create/resume and policy changes.
src/​vs/​platform/​agentHost/​node/​copilot/​sandboxConfigForSdk.ts Updates documentation for extra read-only paths.
src/​vs/​platform/​agentHost/​node/​copilot/​copilotSessionSandbox.ts Supplies the application root to SDK sandbox configuration.
src/​vs/​platform/​agentHost/​node/​copilot/​agentHostSandboxEngine.ts Supplies the application root to the custom-terminal sandbox.
src/​vs/​platform/​agentHost/​common/​vscodeSandboxPaths.ts Includes application contents in shared sandbox read roots.
src/​vs/​platform/​agentHost/​AGENTS.md Documents application-root behavior and SDK policy restrictions.

Review effort: Balanced

Derive the application bundle root from the native environment and include it in host sandbox read defaults. Preserve explicit denies and managed read-only restrictions.

Fixes microsoft#346105

Co-authored-by: Copilot <[email protected]>
Register the application bundle root in launcher fixtures and limit the permission-error fixture to omitting the Copilot home service.

Co-authored-by: Copilot <[email protected]>
Grant application resources and individual runtime files instead of recursively exposing Windows and Linux installation directories. Apply the same bounded roots to both Agent Host sandbox backends and cover portable and versioned layouts.

Co-authored-by: Copilot <[email protected]>
Supply the native environment app root and bundle root required by the terminal sandbox adapter. Keep production read-grant validation unchanged.

Co-authored-by: Copilot <[email protected]>
Merged via the queue into microsoft:main with commit a092ff7 Nov 16, 2026
37 of 38 checks passed
@dileepyavan
Dileep Yavanmandha (dileepyavan) deleted the DileepY/canvas-sandboxing branch November 16, 2026 05:39
@vs-code-engineering vs-code-engineering Bot added this to the 1.148.0 milestone Nov 16, 2026
@dileepyavan Dileep Yavanmandha (dileepyavan) added ~release-cherry-pick Trigger: cherry-pick this PR to the latest release branch release-cherry-pick Automated cherry-pick between release and main branches and removed ~release-cherry-pick Trigger: cherry-pick this PR to the latest release branch release-cherry-pick Automated cherry-pick between release and main branches labels Nov 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

~release-cherry-pick Trigger: cherry-pick this PR to the latest release branch

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Agents window: canvases silently fail to open when "Sandboxing for terminal" is on

4 participants