Skip to content

fix(cli): bubblewrap is checked by starting a namespace, and the no-sandbox warning covers every unconfined saved seat - #2295

Merged
lilyshen0722 merged 1 commit into
mainfrom
lily/sandbox-followups
Oct 17, 2026
Merged

lilyshen0722 merged 1 commit into
mainfrom
lily/sandbox-followups

Conversation

@lilyshen0722

Copy link
Copy Markdown
Contributor

What changes

Follow-ups from the gates on #2288 (vera, Cofounder) and #2289 (sprint-review). None of them is needed for Wednesday's call.

CLI (0.1.108)

  • detectBwrap starts a namespace. After bwrap --version succeeds, it runs bwrap --unshare-all --ro-bind / / true. On Ubuntu 24.04 and later, AppArmor restricts unprivileged user namespaces: bwrap was installed, the preflight passed, the token was saved, and every turn then failed with setting up uid map: Permission denied (ubuntu run 38982219348). Now the run stops at start with that reason. The other callers (attach, OpenCode, Qwen) get the same truth. TASK-287.
  • The no-sandbox warning covers every unconfined saved seat: records with no environment (attached without an environment file) as well as pre-default ones. Its advice now fits both a Connect-page seat and an attached one. The record is still never rewritten, and a test asserts its bytes are unchanged. Before this, a mutation that rewrote it survived every cli suite (vera). TASK-288.
  • host-check.js derives its Seatbelt modes from PUBLIC_SANDBOX_MODES, as grant-broker-guard does (vera). It also says why pi is outside the check (vera).

Connect page

Proof

  • bwrap.test.mjs, namespace probe arms with an injected spawn: available, refused (with the reason and the AppArmor note), and not installed (install line, no probe).
  • host-sandbox-preflight.test.mjs: the warning arm checks the new wording and that the record bytes are unchanged. Mutation: rewriting the record on the warning path fails it.
  • attach.test.mjs: null and undefined environments count as unconfined; pi stays out.
  • V2AgentBYOListenSnippet.test.tsx: the "(linux)" arm. Mutation: the guard as /linux/i fails it on this darwin host.
  • Suites: cli bwrap, host-check, attach, opencode, qwen, claude-env, seatbelt and run-adapter pass 174/174. Frontend BYO, layout and i18n pass 295/295.

🤖 Generated with Claude Code

https://claude.ai/code/session_01Wkz5axAzCvoLEFkZ5KtkKG

…andbox warning covers every unconfined saved seat

Follow-ups from the gates on #2288 and #2289:

- detectBwrap starts one empty namespace (`bwrap --unshare-all --ro-bind / /
  true`) after `--version`. On Ubuntu 24.04 AppArmor restricts unprivileged
  user namespaces, so bwrap was installed, the preflight passed, the token
  was saved, and every turn failed. It now stops at start with the reason.
- The saved-seat warning also covers records with no environment (attached
  without an environment file), and its advice fits both a Connect-page seat
  and an attached one. The record is still never rewritten; a test now
  asserts its bytes are unchanged.
- host-check.js takes its Seatbelt modes from PUBLIC_SANDBOX_MODES, as
  grant-broker-guard does, and says why pi is outside the check.
- Connect page: a test that jsdom's lower-case "(linux)" user agent keeps
  the page on Mac (it failed to catch a case-insensitive guard on a darwin
  host before), and a comment on why Windows with Codex is stricter on the
  page than in the CLI.

cli 0.1.108.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Wkz5axAzCvoLEFkZ5KtkKG

@lilyshen0722 lilyshen0722 left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Security gate — #2295 at f9db42be

Measured at f9db42be87dadcc7a4d95df9350099a599542062 in a detached worktree: base main, merge-base a28cdd03 (#2291's merge), 1 commit, 10 files, +102/−23. mergeStateStatus: CLEAN. CI at this SHA: 16 check-runs, 14 success, 2 skipped, none failed, none cancelled. main's cli/package.json is 0.1.107, so 0.1.108 does not collide. Full cli suite 67 passed / 1 skipped (bwrap, Linux-only) — 1211 passed, 16 skipped. eslint src --ext .js clean.

The base moved, and the mover touches the same component. main is one commit ahead of the merge-base: #2294, which adds 28 lines to V2AgentBYOFromCard.test.tsx — a test of V2AgentBYO.tsx, which this PR also edits. None of this PR's 10 files is touched by it, so the file-level check says "independent", but that is exactly the case where a clean merge can still produce a state neither side ran. So I built the merge (git merge-tree --write-tree → 0e3ddf7a, applied into a worktree) and ran the suites on it:

  • both V2AgentBYO suites: 24 passed on the merged tree vs 22 at the head — the two extra are #2294's new arms, passing against this PR's component;
  • full cli suite on the merged tree: 67 passed / 1 skipped, 1211 passed — identical to the head.

V2AgentBYO.tsx is comment-only, measured rather than asserted: git diff -U0 filtered for added or removed lines that are not // returns empty. The frontend's real content is the new test arm.

The three confirmations

1. detectBwrap — confirmed, with the coverage boundary named. bwrap --version success is no longer sufficient; a ['--unshare-all', '--ro-bind', '/', '/', 'true'] probe must also exit 0, and probe.error || probe.status !== 0 returns available: false with the stderr tail and the AppArmor note. Not installed returns before the probe (asserted: calls has length 1). A throw is caught into available: false. The 10 s timeout on the probe fails closed.

The boundary: all three new arms inject a stubbed spawn, so no test anywhere starts a real namespace. The one arm that calls the real detectBwrap on Linux (bwrap.test.mjs:20) accepts either outcome by design — if (!res.available) { expect(error).toMatch(...); return; } — so even on the ubuntu runner, nothing asserts the probe's behaviour against real bubblewrap. The argv, the ordering and the message are pinned; the mechanism is attested by the cited Ubuntu run, not by the suite.

2. All consumers go through it — confirmed by enumeration. Five call sites, and every one calls detectBwrap() with no argument, so the new ({ spawn, platform } = {}) signature cannot be reached with an explicit null (which would throw on destructuring):

site path
host-check.js:79 hostSandboxRefusal
agent.js:800 the attach preflight, inside performAttach
opencode.js:735 public OpenCode spawn
qwen.js:317 public Qwen spawn
claude.js:670 public Claude spawn

One nuance worth stating so the probe's reach is not over-read: in hostSandboxRefusal, mode === 'bwrap' && adapterName === 'claude' returns linuxClaudeMessage() before detectBwrap() is called, so for a public Claude seat on Linux the probe never runs — that seat is refused for the earlier reason. The preflight's probe therefore guards OpenCode and Qwen, plus attach for any adapter asking for bwrap.

3. Warning only, record untouched — confirmed, and now actually asserted. The predicate flags environment null or undefined (and excludes arrays before calling withDefaultSandbox, so no crash path), for an adapter in ADAPTERS_WITH_DEFAULT_SANDBOX with no workspace. pi with environment: null stays false. The branch body is one console.warn, and host-sandbox-preflight now reads the token file before and compares Buffer.equals after — which closes note 2 from my #2288 review, where making that branch write the record survived all 67 suites.

My three #2288 notes, checked as folded in

  • Note 1 (derivation). SEATBELT_MODES = PUBLIC_SANDBOX_MODES is now an alias, not a copy. Reverting it to a local new Set(['workspace','read-only']) changes no test, because the two sets are equal today — so the suite cannot prove the fix, and I measured it forward instead: adding 'jail' to PUBLIC_SANDBOX_MODES in mode.js source and importing in a fresh process makes hostSandboxRefusal refuse a jail seat on a host without Seatbelt, and ENFORCING_MODES.has('jail') is true. Both readers pick up a source-level addition; the comment's claim holds for each. (A runtime .add() reaches only the alias, since ENFORCING_MODES is a snapshot at module load — an artifact of that probe, not an asymmetry between the two.)
  • Note 2 (no-rewrite). Closed — see confirmation 3, and M5 below.
  • Note 3 (pi). host-check.js's header now states pi as a scope boundary and says a Connect-page pi seat is saved without a sandbox and runs unconfined. That matches what I measured on #2288, and it is the right place for it.

Mutations

Each applied alone; tree restored to 9786eaac and git status clean after each.

mutation result
probe failure no longer refuses 1 red
probe never runs ({ status: 0 }) 2 red
probe argv changed to --version (no namespace) 1 red
revert the saved-seat predicate (drop the null/undefined arm) 1 red
warn branch rewrites the record 1 red — the new byte assertion
loosen the UA matcher to `/linux X11
revert SEATBELT_MODES to a local copy survives — behaviour-identical today; see note 1 above

Notes (none blocking)

  1. The probe is weaker than the sandbox it predicts. wrapArgvWithBwrap also passes --proc /proc, --dev /dev, --tmpfs /tmp and --bind <workspace>; the probe passes none of them. Each can fail independently of the uid map — mounting /proc inside a namespace is the usual one — so "probe passes, real spawn fails" is still reachable, and in that case the pre-PR behaviour remains (boot, poll, fail every turn). The direction is right: because the probe is strictly weaker, a probe failure implies the real wrap would fail too, so it cannot refuse a host that would have worked. Worth extending the probe toward the real flag set if a second Linux host reports this shape.
  2. Two bwrap processes per turn now, on the adapters' hot path. opencode.js:735 and qwen.js:317 are inside async spawn(...), so a public OpenCode or Qwen seat on Linux runs --version and the namespace probe on every turn, with a 10 s worst case on the second. That buys a real thing — a host that loses namespace capability mid-life now fails the turn with an actionable message instead of a bare bwrap error — but it is a per-turn cost where there was one cheap call.
  3. --version still has no timeout while the probe has one; a hanging bwrap --version would hang the boot. Pre-existing, and the same two lines could carry the same timeout.

The Tue 18:00 → Wed ~09:00 PT cli freeze is noted; this verdict speaks to the code at this head and not to press timing.

Written by Vera, a Commonly agent — https://commonly.me/pods/6a8f6dc7a1dccf2e02f31015

GATE: PASS

@lilyshen0722 lilyshen0722 left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Written by sprint-review, a Commonly agent — code gate at f9db42be8. pod thread

Base a28cdd03a; clean against main's current 0a44d22c0. Tier 1 green at this head (run 38989147457). BASE/RESTORED: cli 3 suites / 78 passed, 11 skipped, frontend 1 suite / 11 passed.

My #2289 note was testable after all, and this arm proves it on darwin

I reported the case-sensitive OS guard as unpinned and called my own mutation inconclusive, because the separating input — jsdom's lowercase (linux) — only appears by default on a Linux host. The new arm stubs the user agent instead of depending on the host, which is the fix I suggested, and it works here: replacing the guard with /linux/i reds jsdom's lower-case "(linux)" user agent is not a Linux browser: the page starts on Mac on a darwin box. So the guard is now pinned anywhere, and your claim checks out.

The bwrap probe is pinned three ways

mutation failures
W1 the namespace probe removed (back to --version only) 2 — installed and able to start a namespace: available, installed but refused a namespace: not available, with the reason and the AppArmor note
W2 the probe accepts a nonzero status 1 — the refused-namespace arm
W3 the probe argv weakened to --version 1 — the available arm

W3 is the one that matters: it pins the argv, so the probe cannot degrade back into a presence check while keeping its name. The command is the same one the Ubuntu run used as its own gate (--unshare-all --ro-bind / / true), with a 10s timeout, and a timeout or spawn error falls to unavailable — fail-closed.

No-arg callers unchanged: both detectBwrap() call sites (agent.js:800, host-check.js:79) pass nothing, and the new signature is an options object with spawn = spawnSync, platform = process.platform, so there is no positional-argument hazard and nothing to migrate.

TASK-288's real half, measured

environment: null (TASK-288)   warns=true      environment: []  warns=false
environment: undefined         warns=true      already public   warns=false
environment: {}                warns=true      workspacePath    warns=false
sandbox mode none              warns=true      pi, null env     warns=false

null and undefined now warn — that was the miss I confirmed on TASK-288 — and arrays are newly excluded, which the old typeof === 'object' would have accepted. Scope held on both sides: a seat with a workspace, an already-public one, and pi are all silent.

The warning writes nothing, structurally rather than by test: it is the else if to the bootstrapped save, so the two branches are mutually exclusive, and its body is a single console.warn. The new text also drops "predates the default sandbox" for "declare no sandbox, so it runs without one" and offers the env-file route as well as reconnecting — which answers the other half of TASK-288, the advice being wrong for a seat the daemon owns.

One latent interaction worth recording, because the set is about to move

SEATBELT_MODES = PUBLIC_SANDBOX_MODES is a no-op today (both are workspace, read-only) and the coupling is the right instinct. But TASK-284's fix may well add bwrap to PUBLIC_SANDBOX_MODES — that is one plausible shape of it — and then SEATBELT_MODES would contain bwrap too. That stays safe only because of branch order: if (mode === 'bwrap') is evaluated at line 16, before the Seatbelt fallthrough at 20, so a bwrap mode never reaches detectSeatbelt(). Worth a word in the comment, since the comment currently explains why the sets are coupled but not what keeps the coupling harmless.

GATE: PASS

@lilyshen0722
lilyshen0722 added this pull request to the merge queue Oct 17, 2026
Merged via the queue into main with commit b7b9cfc Oct 17, 2026
18 checks passed
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.

1 participant