Repository navigation
fix(sandbox): require path protection for the sandbox modes - #1235
Merged
Merged
Conversation
K-brain v0.107.21 falls back to Landlock on Linux when bubblewrap is unusable and reports run_sandbox.path_protection=false: .liveagent, .k-brain, .git/hooks and .git/config stay writable inside the sandbox and are later used outside it. Treat such a sandbox as unavailable: the desktop selector disables Sandbox and Offline sandbox with an explanation, and the desktop client and the Gateway refuse to submit options.sandbox. A missing field (older K-brain) counts as protected unless the mechanism is landlock. Closes #1234
This was referenced Nov 5, 2026
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 #1234
Depends on #1233 (pin bundled K-brain to v0.107.21): that K-brain adds the Linux Landlock fallback and the
run_sandbox.path_protectionfield. This PR is safe to merge on its own (older K-brain omits the field and behaves as before), and it should land before or together with #1233, which otherwise failspermission-modes-backend.test.mjs›sandbox-protectedon the Linux runner.Summary
With bubblewrap unusable, K-brain v0.107.21 sandboxes commands with Landlock and reports
run_sandbox: { supported: true, mechanism: "landlock", network_control: true, read_masking: false, path_protection: false }. Without path protection,.liveagent/,.k-brain/,.git/hooksand.git/configare writable inside the sandbox, and those files are later used outside it, so a sandboxed command can escape. LiveAgent's Sandbox modes promise those paths stay read-only, so LiveAgent now requires path protection:path_protection === falsemeans the sandbox is unavailable for both Sandbox and Offline sandbox.chat.safety.sandboxUnavailablefollowed by a newchat.safety.sandboxNoPathProtectionexplanation.supportsRunSandbox) and the Gateway (SupportsRunSandbox/requireRunOptions) refuse to submitoptions.sandboxwith a clear error, so a stale UI setting or a WebUI request can't run with protected paths writable.landlockmechanism counts as unprotected, but no released K-brain sends that combination. An unsupported sandbox keeps K-brain's own reason.read_maskinghandling (sandboxDescNoReadMask) is unchanged.Change scope
crates/agent-ui/src/lib/kbrain/health.ts: newrunSandboxLacksPathProtection, used bysupportsRunSandboxcrates/agent-gui/src/agent-ui-adapters/sandboxCapability.ts: desktop capability reportssupported: falseandpath_protection: falsecrates/agent-ui/src/components/chat/CommandSafetyModeSelector.tsx, plus the en-US and zh-CN translationscrates/agent-gui/src/lib/kbrain/client.ts: refusal messagecrates/agent-gateway/internal/kbrain/health.go: same gate for WebUI and remote runscrates/agent-gateway/web/src/agent-ui-adapters/sandboxCapability.ts: type onlydocs/kbrain-permission-modes.mdScreenshots / preview
How this was produced: I ran the real desktop app, a debug
target/debug/liveagentfrom this branch with the Vite dev server, isolated withLIVEAGENT_DEV_HOME/HOMEset to temp dirs. ItsLIVEAGENT_KBRAIN_BINARYpoints to a wrapper that starts a real K-brain v0.107.21 backend in an Ubuntu 24.04 container (linux/arm64, no bubblewrap). That binary was built from thev0.107.21tag, because the release ships no linux-arm64 asset and the x64 release under emulation has no Landlock. Nothing in the health response is stubbed. K-brain itself reported"mechanism": "landlock", "supported": true, "network_control": true, "read_masking": false, "path_protection": false. The app UI was in zh-CN; I opened the selector through the debug build's dev bridge and took the image with the bridge's native window capture, then cropped it to the composer area (sidebar removed).Verification
node --test test/chat/permission-modes.test.mjs test/chat/command-safety-mode-selector.test.mjs: new cases coverpath_protection: false(unavailable online and offline, run refused before any POST), field missing (unchanged),true(available), Landlock without the field, an unsupported sandbox keeping its own reason, and the selector hint for both entries.permission-modes-backend.test.mjs: the sandbox cases now also requirepath_protection !== false. When K-brain reports a supported but unprotected sandbox, a newsandbox-without-path-protectioncase checks that the client refuses the run.path_protection: true): 13/13 pass, sandbox cases run.sandbox-protected, the same failure as on chore(release): pin bundled K-brain to v0.107.21 #1233. This branch: the refusal case passes, the two sandbox cases are skipped, 0 failures.cd crates/agent-gateway && go test ./...: pass, with newTestRunSandboxCapabilityBeforeSubmissioncases.pnpm test:gui(4107 pass, 0 fail),pnpm test:webui(884 pass),pnpm typecheck:ui,typecheck:gui,typecheck:webui,check:ui-boundaries, and biome on the changed files.Pre-submit checklist