Skip to content

Agent Host: secondary window/profile overwrites shared sandbox root config and enables sandbox for other windows #349914

Open

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

  1. AgentHostSandboxForwarder overwrites the host-wide sandbox root config on every window connect / configuration change:

    • In src/vs/workbench/contrib/terminalContrib/chatAgentTools/browser/agentHostSandboxForwarder.ts, each workbench window independently pushes readAgentHostSandboxValues(...) via ActionType.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 defaults chat.agent.sandbox.enabled to "on", or any profile with different sandbox settings) overwrites the shared Agent Host's agent-host-config.json sandbox object.
    • That host-wide mutation immediately applies to running sessions and persists for new sessions created in other windows using the Default profile.
  2. 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 the RootConfigChanged, making it very hard to diagnose why sandbox mode flipped unexpectedly.

Observed Timeline (anonymized)

Setup:

  • Default profile explicitly sets "chat.agent.sandbox.enabled": false and "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 — AgentHostSandboxForwarder in 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.update
  • 12: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 access
  • 13: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, leaving allowLocalNetwork: false behind in agent-host-config.json even though the Default profile has allowLocalNetwork: 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.log should log the effective sandbox flags (e.g. enabled, allowLocalNetwork) and the originating client/source when sandbox root config changes or applySandboxConfig runs.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

bug

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions