Repository navigation
Description
Problem
Opening or switching a secondary VS Code window to another profile can silently turn sandbox mode on (and overwrite other sandbox settings like allowLocalNetwork) for all windows and subsequent sessions sharing the same Agent Host — even when the user's Default profile explicitly disables sandboxing ("chat.agent.sandbox.enabled": false / "off").
From the user's perspective, sessions in their main window appear to randomly enable sandbox mode and break local MCP servers (host 127.0.0.1 is local and the sandbox policy does not allow local network access).
Root Cause
-
AgentHostSandboxForwarderoverwrites the host-widesandboxroot config on every window connect / configuration change:- In
src/vs/workbench/contrib/terminalContrib/chatAgentTools/browser/agentHostSandboxForwarder.ts, each workbench window independently pushesreadAgentHostSandboxValues(...)viaActionType.RootConfigChanged(config: { sandbox: desired }) whenever a connection comes online or sandbox settings change. readAgentHostSandboxValues(src/vs/workbench/contrib/terminalContrib/chatAgentTools/common/sandboxSettingsReader.ts) reads the effective setting values for that window's profile, including registered/experiment defaults.- Because forwarding is last-writer-wins across all connected windows and profiles, any secondary window using a profile that does not explicitly override
chat.agent.sandbox.enabled(e.g., an empty/test profile when an experiment defaultschat.agent.sandbox.enabledto"on", or any profile with different sandbox settings) overwrites the shared Agent Host'sagent-host-config.jsonsandboxobject. - That host-wide mutation immediately applies to running sessions and persists for new sessions created in other windows using the Default profile.
- In
-
Diagnostics gap in
agenthost.log:applySandboxConfig(src/vs/platform/agentHost/node/copilot/copilotSessionLauncher.ts) only logs:
Applied SDK sandboxConfig via session.options.update- It does not log the applied values (such as
enabled,allowLocalNetwork) or which client/window dispatched theRootConfigChanged, making it very hard to diagnose why sandbox mode flipped unexpectedly.
Observed Timeline (anonymized)
Setup:
- Default profile explicitly sets
"chat.agent.sandbox.enabled": falseand"chat.agent.sandbox.network.allowLocalNetwork": true. - A secondary profile has no
chat.agent.sandbox.*settings, so it inherits the experiment default (enabled: "on",allowLocalNetwork: false).
Observed sequence in agenthost.log and renderer logs:
12:58:12.329— Session<session-1>starts with sandbox off; local MCP servers connect normally (12:58:13.344).12:58:48.666— A secondary window switches to the secondary profile (no sandbox overrides).12:58:50.897—AgentHostSandboxForwarderin that secondary window pushes the secondary profile's effective sandbox config (enabled: "on",allowLocalNetwork: false) to the shared Agent Host root config:
[Copilot:<session-1>] Applied SDK sandboxConfig via session.options.update12:58:51.900— Local MCP servers immediately fail:
MCP server '<local-mcp>' failed (error): ... host 127.0.0.1 is local and the sandbox policy does not allow local network access13:05:40.548— A new session<session-2>started in the main window (Default profile) inherits the overwritten host root config, receives sandboxed-environment instructions, and fails local MCP server startup (13:05:43.254).13:06:05.602— Another new session<session-3>in the main window also starts with sandbox enabled and fails local MCP startup (13:06:08.126).13:06:12.892–13:06:14.124— Sandbox config is updated back to off before<session-3>sends its first turn, leavingallowLocalNetwork: falsebehind inagent-host-config.jsoneven though the Default profile hasallowLocalNetwork: true.
Expected Behavior
- A secondary window / non-default profile connecting to a shared Agent Host should not silently clobber the sandbox configuration of other windows or sessions (e.g., avoid pushing default/unconfigured profile values over explicit host config, or scope sandbox settings per session/window rather than last-writer-wins global
RootConfigChanged). agenthost.logshould log the effective sandbox flags (e.g.enabled,allowLocalNetwork) and the originating client/source whensandboxroot config changes orapplySandboxConfigruns.
Activity