Skip to content

fix(cli): apply sandbox settings to existing sessions - #12600

Open
marius-kilocode wants to merge 7 commits into
mainfrom
marius-kilocode/sandbox-session-policy-hint
Open

fix(cli): apply sandbox settings to existing sessions#12600
marius-kilocode wants to merge 7 commits into
mainfrom
marius-kilocode/sandbox-session-policy-hint

Conversation

@marius-kilocode

@marius-kilocode marius-kilocode commented Jul 28, 2026

Copy link
Copy Markdown
Collaborator

Sandbox network mode, allowed destinations, and writable paths were previously fixed when a session initialized. Saving a corrected path or network policy left that session on stale authority, so users had to abandon otherwise valid conversations and start over.

The user workflow is now: change the sandbox settings, click Save, and continue in the same session. The next tool execution automatically uses the updated network mode, allowed destinations, and writable paths. No new session, VS Code restart, extension restart, or sandbox toggle is required.

If sandboxing is disabled, changing settings and then enabling it also uses the latest settings.

This change applies trusted sandbox setting changes to existing sessions before their next tool execution:

  • Saving settings updates sidebar, editor, forked, subagent, and Agent Manager sessions without replacing conversation state.
  • Enabling sandboxing reads the latest network, destination, and writable-path settings.
  • A tool already running finishes under its starting policy, while queued and subsequent tools use the updated policy.
  • Each session keeps its enabled or disabled choice. The saved sandbox.enabled value remains the default for new sessions.

Creation-time inheritance still gives child sessions the stricter parent/child policy. Later trusted user settings intentionally replace those network and writable-path limits across existing sessions.

To keep this authority update user-controlled, model-launched shell, local MCP, formatter, and language-server processes do not inherit backend server credentials or Kilo config environment variables. They cannot use authenticated configuration endpoints or injected config content to change their own sandbox policy.

The sandboxing documentation describes the live behavior and timing.

@marius-kilocode
marius-kilocode enabled auto-merge (squash) July 28, 2026 12:00
Each initialized session snapshots its network mode, allowed destinations, and additional writable paths. Changing config affects new sessions. The prompt control or `/sandbox` can change the current session's enabled state, but it cannot change these authority lists, and they never expand during an active session.

{% callout type="info" %}
Restarting VS Code or the extension does not refresh an existing session's sandbox policy. After changing network mode, allowed destinations, or writable paths, start a new session to pick up the updated settings.

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.

I thought disabling/re-enabling also refreshes it?

@kilo-code-bot

kilo-code-bot Bot commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

Code Review Summary

Status: No Issues Found | Recommendation: Merge

Overview

Incremental diff since the last review (1f53963b) touches only one file: packages/opencode/test/kilocode/sandbox/state.test.ts. The uses current settings when enabling an initialized policy test now guards on status.available: when the sandbox backend is unavailable in the test environment, it asserts toggle leaves the session disabled with version: 0 and a deny-mode/no-write policy, then returns early instead of asserting the enabled/version: 1 path. This mirrors the same !status.available guard already used elsewhere in this file and is a test-only robustness fix for CI environments without a sandbox backend, with no functional code change.

The two previously-flagged WARNINGs (env.ts credential-stripping scope, policy.ts trust-boundary note) remain resolved at current HEAD: env.ts deletes KILO_CONFIG/KILO_CONFIG_CONTENT/KILO_CONFIG_DIR alongside the server credentials, and policy.ts no longer polls raw config files, refreshing only from the trusted global.config.updated bus event.

Files Reviewed (1 file)
  • packages/opencode/test/kilocode/sandbox/state.test.ts
Previous Review Summaries (5 snapshots, latest commit 1f53963)

Current summary above is authoritative. Previous snapshots are kept for context only.

Previous review (commit 1f53963)

Status: No Issues Found | Recommendation: Merge

Overview

Incremental diff since the last review (17af2a8) touches only one file: packages/opencode/test/kilocode/tool/shell-env.test.ts. The Windows branch of the credential-isolation test was updated from checking two env vars via cmd-style syntax to checking all five (KILO_SERVER_PASSWORD, KILO_SERVER_USERNAME, KILO_CONFIG, KILO_CONFIG_CONTENT, KILO_CONFIG_DIR) using PowerShell $env: syntax, matching the Unix branch's existing scope and the default shell resolution used by ShellTool on Windows. This is a test-only correctness improvement with no functional code change.

The two previously-flagged WARNINGs (env.ts credential stripping scope, policy.ts trust-boundary note) are already resolved at current HEAD and their GitHub comments are now outdated (line: null), consistent with the prior review.

Files Reviewed (1 file)
  • packages/opencode/test/kilocode/tool/shell-env.test.ts

Previous review (commit 17af2a8)

Status: No Issues Found | Recommendation: Merge

Overview

Both previously flagged WARNINGs remain resolved at current HEAD:

  • packages/opencode/src/kilocode/process/env.ts's model() strips KILO_SERVER_PASSWORD, KILO_SERVER_USERNAME, KILO_CONFIG, KILO_CONFIG_CONTENT, and KILO_CONFIG_DIR before being used by formatters, LSP launch, MCP servers, and model shell commands, closing the config-content credential leak path (covered by test/kilocode/tool/shell-env.test.ts).
  • packages/opencode/src/kilocode/sandbox/policy.ts refreshes session policy only from the trusted global.config.updated GlobalBus event (via an in-memory revision counter), not from raw config-file polling, keeping the trust boundary scoped to the settings API.

The rest of the diff (docs wording update describing the new live-refresh timing, i18n string cleanup removing the now-stale "changes apply to new sessions" caveat across 21 locales, a sandbox/state.ts formatting fix, and a renamed changeset) is consistent with the code changes and introduces no new issues. New sandbox policy tests (state.test.ts, config-overlay.test.ts) exercise the refresh-on-toggle, refresh-on-next-tool-execution, and inheritance-refresh behavior against real config layers rather than mocking the logic under test.

Files Reviewed (33 files)
  • .changeset/sandbox-live-settings.md
  • packages/kilo-docs/pages/getting-started/settings/sandboxing.md
  • packages/kilo-vscode/webview-ui/src/i18n/*.ts (21 locales)
  • packages/opencode/src/format/index.ts
  • packages/opencode/src/kilocode/process/env.ts
  • packages/opencode/src/kilocode/sandbox/policy.ts
  • packages/opencode/src/kilocode/sandbox/state.ts
  • packages/opencode/src/kilocode/sandbox/store.ts
  • packages/opencode/src/lsp/launch.ts
  • packages/opencode/src/mcp/index.ts
  • packages/opencode/src/tool/shell.ts
  • packages/opencode/test/kilocode/sandbox/state.test.ts
  • packages/opencode/test/kilocode/server/config-overlay.test.ts
  • packages/opencode/test/kilocode/tool/shell-env.test.ts

Previous review (commit 33f93b2)

Status: No Issues Found | Recommendation: Merge

Overview

Both previously flagged WARNINGs are resolved in this update:

  • packages/opencode/src/kilocode/process/env.ts now also strips KILO_CONFIG, KILO_CONFIG_CONTENT, and KILO_CONFIG_DIR from model(), closing the config-content credential leak path (covered by an updated test in shell-env.test.ts).
  • packages/opencode/src/kilocode/sandbox/policy.ts removed the raw-file polling (externalConfig()/configFiles) that widened the trust boundary; policy revision bumps now come solely from the trusted global.config.updated bus event.

The remaining diff (docs wording tweak, removal of the now-redundant settings.sandboxing.hint UI hint across all 21 locales + its CSS rule, and a changeset rename) is consistent and introduces no new issues.

Files Reviewed (27 files, incremental since 5b37f18)
  • .changeset/sandbox-live-settings.md (renamed from sandbox-session-policy-hint.md)
  • packages/kilo-docs/pages/getting-started/settings/sandboxing.md
  • packages/kilo-vscode/webview-ui/src/components/settings/SandboxingTab.tsx
  • packages/kilo-vscode/webview-ui/src/styles/settings.css
  • packages/kilo-vscode/webview-ui/src/i18n/*.ts (21 locales)
  • packages/opencode/src/kilocode/process/env.ts - previous WARNING resolved
  • packages/opencode/src/kilocode/sandbox/policy.ts - previous WARNING resolved
  • packages/opencode/test/kilocode/tool/shell-env.test.ts

Previous review (commit 5b37f18)

Status: 2 Issues Found | Recommendation: Address before merge

Overview

Severity Count
CRITICAL 0
WARNING 2
SUGGESTION 0
Issue Details (click to expand)

WARNING

File Line Issue
packages/opencode/src/kilocode/process/env.ts 8 model() strips KILO_SERVER_PASSWORD/KILO_SERVER_USERNAME from formatter/LSP/MCP/shell subprocess env but not KILO_CONFIG_CONTENT (which can carry provider apiKeys), leaving a similar leak path open
packages/opencode/src/kilocode/sandbox/policy.ts 41 externalConfig() polls raw files under Global.Path.config and bumps revision on any content change, so any process with write access there (not just the trusted /config/overlay route) can trigger mid-session policy widening for all active sandboxed sessions
Files Reviewed (33 files, incremental since 700b539)
  • .changeset/sandbox-session-policy-hint.md
  • packages/kilo-docs/pages/getting-started/settings/sandboxing.md
  • packages/kilo-vscode/webview-ui/src/i18n/*.ts (21 locales)
  • packages/opencode/src/format/index.ts
  • packages/opencode/src/kilocode/process/env.ts - 1 issue
  • packages/opencode/src/kilocode/sandbox/policy.ts - 1 issue
  • packages/opencode/src/kilocode/sandbox/state.ts
  • packages/opencode/src/kilocode/sandbox/store.ts
  • packages/opencode/src/lsp/launch.ts
  • packages/opencode/src/mcp/index.ts
  • packages/opencode/src/tool/shell.ts
  • packages/opencode/test/kilocode/sandbox/state.test.ts
  • packages/opencode/test/kilocode/server/config-overlay.test.ts
  • packages/opencode/test/kilocode/tool/shell-env.test.ts

This commit does two things: (1) makes sandbox network/writable-path/allowed-host settings refresh existing sessions from trusted global config instead of only affecting new sessions (resolves the previously-flagged doc question about disable/re-enable refresh), and (2) strips KILO_SERVER_PASSWORD/KILO_SERVER_USERNAME from the env passed to formatters, LSP servers, MCP servers, and model shell commands. Test coverage for both is solid, including a regression test confirming untrusted project-level config can't weaken an initialized policy. The two warnings above are about scope/completeness of the new behavior, not correctness bugs in what's implemented.

Fix these issues in Kilo Cloud

Previous review (commit 700b539)

Status: No Issues Found | Recommendation: Merge

Files Reviewed (24 files)
  • .changeset/sandbox-session-policy-hint.md
  • packages/kilo-docs/pages/getting-started/settings/sandboxing.md
  • packages/kilo-vscode/webview-ui/src/components/settings/SandboxingTab.tsx
  • packages/kilo-vscode/webview-ui/src/i18n/ar.ts
  • packages/kilo-vscode/webview-ui/src/i18n/br.ts
  • packages/kilo-vscode/webview-ui/src/i18n/bs.ts
  • packages/kilo-vscode/webview-ui/src/i18n/da.ts
  • packages/kilo-vscode/webview-ui/src/i18n/de.ts
  • packages/kilo-vscode/webview-ui/src/i18n/en.ts
  • packages/kilo-vscode/webview-ui/src/i18n/es.ts
  • packages/kilo-vscode/webview-ui/src/i18n/fr.ts
  • packages/kilo-vscode/webview-ui/src/i18n/it.ts
  • packages/kilo-vscode/webview-ui/src/i18n/ja.ts
  • packages/kilo-vscode/webview-ui/src/i18n/ko.ts
  • packages/kilo-vscode/webview-ui/src/i18n/nl.ts
  • packages/kilo-vscode/webview-ui/src/i18n/no.ts
  • packages/kilo-vscode/webview-ui/src/i18n/pl.ts
  • packages/kilo-vscode/webview-ui/src/i18n/ru.ts
  • packages/kilo-vscode/webview-ui/src/i18n/th.ts
  • packages/kilo-vscode/webview-ui/src/i18n/tr.ts
  • packages/kilo-vscode/webview-ui/src/i18n/uk.ts
  • packages/kilo-vscode/webview-ui/src/i18n/zh.ts
  • packages/kilo-vscode/webview-ui/src/i18n/zht.ts
  • packages/kilo-vscode/webview-ui/src/styles/settings.css

All 20 locale dictionaries were updated consistently (new settings.sandboxing.hint key added, redundant "changes apply to new sessions" sentence removed from allowedHosts.description). The changeset is present and user-facing. Docs callout usage matches existing Markdoc conventions in this repo. No bugs, security issues, fork-hygiene concerns, or missing tests identified in the changed code.


Reviewed by claude-sonnet-5 · Input: 42 · Output: 10.6K · Cached: 1.2M

Review guidance: REVIEW.md from base branch main

@marius-kilocode
marius-kilocode disabled auto-merge July 28, 2026 12:09
@marius-kilocode marius-kilocode changed the title feat(vscode): add sandbox settings hint for session-scoped policy fix(cli): apply sandbox settings to existing sessions Jul 29, 2026
@marius-kilocode
marius-kilocode enabled auto-merge (squash) July 29, 2026 09:00
),
)
delete env.KILO_SERVER_PASSWORD
delete env.KILO_SERVER_USERNAME

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.

WARNING: model() only strips KILO_SERVER_PASSWORD/KILO_SERVER_USERNAME, not KILO_CONFIG_CONTENT

This helper is now used to build the env for formatters (format/index.ts), LSP servers (lsp/launch.ts), MCP servers (mcp/index.ts), and model shell commands (tool/shell.ts) — all non-sandboxed child processes. The sandbox's own environment.deny list in policy.ts treats KILO_CONFIG, KILO_CONFIG_CONTENT, and KILO_CONFIG_DIR as equally sensitive alongside the server credentials, since KILO_CONFIG_CONTENT can carry inline config (including provider apiKey values, see config-injector.ts).

As written, any formatter, LSP server, MCP server, or model-run shell command will still inherit KILO_CONFIG_CONTENT/KILO_CONFIG/KILO_CONFIG_DIR from the parent process even after this fix, leaving a similar credential-leak path open for that variable.


Reply with @kilocode-bot fix it to have Kilo Code address this issue.

if (event.payload?.type === "global.config.updated") revision++
})

function externalConfig() {

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.

WARNING: Raw file polling widens the trust boundary for mid-session policy refresh

externalConfig() re-reads configFiles under Global.Path.config every second and bumps revision whenever their raw content changes, independent of the global.config.updated GlobalBus event that the trusted /config/overlay route emits (per the new config-overlay.test.ts case). That means any process with filesystem write access to the global config directory — not just the settings API — can now cause every active sandboxed session across all directories to pick up new network/writable-path limits before its next tool call, per current().

The dedicated test does not let project config weaken an initialized policy shows project-level config intentionally can't do this, which suggests the mid-session widening is meant to be scoped to genuinely trusted, user-initiated global settings changes. Given the PR's own stated invariant ("a confined agent must not be able to widen its own escape hatch mid-session"), it's worth confirming that nothing with a plausible write path to Global.Path.config (e.g. an agent that briefly runs unsandboxed, or a sibling session sharing the same backend) can use this raw-file channel to widen confinement for other, already-running sessions before their next tool execution.


Reply with @kilocode-bot fix it to have Kilo Code address this issue.

@marius-kilocode
marius-kilocode force-pushed the marius-kilocode/sandbox-session-policy-hint branch from 33f93b2 to 17af2a8 Compare July 29, 2026 10:04
@marius-kilocode
marius-kilocode force-pushed the marius-kilocode/sandbox-session-policy-hint branch from 43ed4b2 to 1f53963 Compare July 29, 2026 10:26
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.

2 participants