Repository navigation
feat(sandbox): set up the Windows offline sandbox from the mode selector - #1239
Merged
Merged
Conversation
K-brain can install its elevated Windows sandbox (two hidden local accounts plus firewall rules for the offline one) behind a UAC prompt via POST /v1/sandbox/setup (Stack-Cairn/K-brain#165). When health reports sandbox_setup 1, run_sandbox.setup_available and no network control yet, the desktop selector offers "Set up offline sandbox…" under the disabled entry. A confirmation dialog lists what setup changes and that kn sandbox uninstall reverts it; the dialog then waits on the administrator prompt and reports each status (ready, self-test still failing, declined, busy, failed with K-brain's message, unsupported, error). Every attempt the backend may have acted on re-reads /v1/health, and the refreshed capability reaches every mounted selector so Offline sandbox becomes selectable. Desktop only and only for a K-brain on this machine; the WebUI adapter never offers it. A sandbox without path protection stays unavailable. Closes #1238
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Linked issue
Closes #1238
Backed by K-brain's elevated sandbox mode, Stack-Cairn/K-brain#165 (released in K-brain v0.107.22).
Summary
On native Windows, K-brain starts with the
low-integritysandbox, which cannot cut the network (network_control: false), so Offline sandbox is disabled. Stack-Cairn/K-brain#165 adds an elevated mode (two hidden local accounts plus WFP firewall rules) andPOST /v1/sandbox/setupto install it behind a UAC prompt. This PR lets desktop users run that setup from the composer's mode selector instead of a terminal.capabilities.sandbox_setup == 1,run_sandbox.setup_available == trueandnetwork_controlis not true. A Set up offline sandbox… item then appears under the disabled Offline sandbox entry, with K-brain'ssetup_hintas its tooltip. fix(sandbox): require path protection for the sandbox modes #1235's rule still holds: a sandbox withpath_protection === falsestays unavailable and is never offered setup.kn sandbox uninstallundoes everything, and shows K-brain's hint.200ready, with Use offline sandbox to switch modes (or "finished, but the self-test still fails" with K-brain's hint if health still lacks network control);403declined, nothing changed;409another setup is running;500failed, with K-brain's message and the uninstall command;501unsupported; anything else, including405and transport errors, a generic error with the message. Every non-ready result except501offers Try again.501(K-brain bumpscapabilityRevision), the desktop re-reads/v1/healththrough a shared capability store, so every mounted selector updates. The re-read capability decides ready or incomplete, not the response alone.setUpOfflineSandboxreturnsunsupported. There is no uninstall button; uninstalling is terminal-only, as in K-brain.Change scope
crates/agent-ui/src/lib/kbrain/health.ts:offersRunSandboxSetup()crates/agent-ui/src/lib/kbrain/sandboxSetup.ts(new): maps the HTTP status and body to an outcomecrates/agent-ui/src/components/chat/OfflineSandboxSetupDialog.tsx(new): confirm, running and result dialogcrates/agent-ui/src/components/chat/CommandSafetyModeSelector.tsx: setup item and dialog wiringcrates/agent-ui/src/i18n/translations/{enUSCommon,zhCNCommon}.ts: en-US and zh-CN stringscrates/agent-gui/src/agent-ui-adapters/kbrainSettings.ts:setUpKBrainSandbox()(authenticated POST with no timeout)crates/agent-gui/src/agent-ui-adapters/sandboxCapability.ts: shared capability store, refresh,setUpOfflineSandbox(), local-backend checkcrates/agent-gui/src/lib/kbrain/types.ts:KBrainRunSandboxCapabilitycrates/agent-gateway/web/src/agent-ui-adapters/sandboxCapability.ts: WebUI never offers setupdocs/kbrain-permission-modes.md: "Windows: setting up the offline sandbox"Screenshots / preview
All screenshots come from the real desktop debug app (macOS arm64,
tauri devbuild), with the sidebar cropped out. The app used temporaryHOME/LIVEAGENT_DEV_HOMEdirectories and ran the real K-brain v0.107.22 release binary. Nothing in the screenshots was drawn or edited apart from cropping.What was injected, and why: the elevated sandbox (UAC,
sandbox-useraccounts, WFP) exists only on native Windows. On macOS, K-brain reports its macOS sandbox and answersPOST /v1/sandbox/setupwith501. To show the Windows flow, a thin loopback proxy sat between the app and the real K-brain and changed exactly two things:GET /v1/health: setcapabilities.sandbox_setupto1and replacedcapabilities.run_sandboxwith K-brain's Windows values (low-integrity,network_control: false,setup_available: true, and thereason/setup_hintstrings copied from K-brain'sinternal/sandbox). After a successful setup it reportedsandbox-userwithnetwork_control: true, andcapabilityRevisionwas bumped per attempt.POST /v1/sandbox/setup: canned K-brain-shaped answers after a short delay that stands in for the UAC prompt: first403(code: "declined"), then200.Every other request, including the run and settings traffic, went to the real K-brain unchanged.
After Use offline sandbox, health was re-read: Offline sandbox is enabled and selected, and the setup action is gone.
Verification
crates/agent-gui:node --test test/chat/offline-sandbox-setup.test.mjs test/chat/command-safety-mode-selector.test.mjspasses, 15/15. New tests cover:sandbox_setup≠ 1,setup_availablefalse,sandbox-user,path_protection: false, remote backend, empty hint.501.onChange("sandboxOffline").test:guiandtest:webuipass. The K-brain backend integration tests were run against the v0.107.22 binary throughLIVEAGENT_KBRAIN_BINARY.pnpm lint,check-mirrorand diff hygiene. The i18n parity test passes for both locales.Pre-submit checklist