Skip to content

fix(cli): refuse before open: a sandbox option the adapter can't enforce fails the seat at start (F535) - #4171

Open
lilyshen0722 wants to merge 6 commits into
mainfrom
swe/f535-refuse-before-open
Open

lilyshen0722 wants to merge 6 commits into
mainfrom
swe/f535-refuse-before-open

Conversation

@lilyshen0722

@lilyshen0722 lilyshen0722 commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

F535: refuse before open

Ported from OAR's rule (D318, CTO verdict 11-15): an option a runtime can't honour is refused before anything opens, never silently dropped. The 11-15 audit on main 10364a0 found sandbox shapes that commonly agent run accepted and then didn't enforce.

Change

  • hermes (packages/seats/src/adapters/hermes.js) ran sandbox.trust=workspace bare, while the unconfined-seat guard read that trust as confined and skipped the private-pod check. It now refuses workspace at spawn, as every adapter but claude does.

  • sandboxOptionRefusal (cli/src/lib/sandbox-option-refusal.js) runs beside providerRefusal in agent config, attach and run. The daemon starts seats through run, so a stored or daemon record can't skip it. It refuses:

    • network.allow-hosts, which no adapter reads;
    • network.policy=restricted under macOS Seatbelt on claude, opencode or qwen, where the profile keeps the network on for the model and MCP (under bwrap, claude and qwen already refuse it and opencode applies it);
    • a sandbox.mode with no public or workspace trust, which spawns bare on claude (except bwrap), opencode and qwen. codex runs such a seat in one private profile (workspace writable, network on), so it keeps mode workspace and refuses read-only;
    • network or filesystem rules on a seat with no trust, which nothing enforces when there's no mode, and which codex's private profile never reads.
  • An open network policy and empty lists ask for nothing, so they pass. That covers the quickstart's macOS shape and examples/demo/demo.yaml, whose comment now says allow-hosts documents intent only.

  • ADR-008 invariant 2 notes the rule.

  • Audit item (5), by Cofounder ruling 11-15: a public seat reads only its workspace. filesystem.read-outside on a public seat is refused at start on every adapter, legacy internal included. opencode and qwen refuse it at spawn too, as goose, pi and claude's bwrap branch already did; before this, bwrap opencode and qwen bound it into the jail. Workspace and private trust keep today's behaviour. No seat record here and no install on prod declares read-outside, so no live seat changes. Attack test: a public bwrap opencode seat asking to read ~/.commonly is refused at start and at spawn, with nothing spawned.

Proof

  • sandbox-option-refusal.test.mjs (29): one case per rule and adapter, plus the shapes that run today and must still start: no sandbox, the default {trust:'public'}, public read-only opencode (hq-support's record), claude workspace trust with an allow list, legacy internal, claude bwrap, codex with a mode, mode none, and the stub.
  • run-loop.test.mjs: a run refuses at start, with no client made and no spawn.
  • adapters.hermes.test.mjs: workspace trust is refused before the probe or spawn. Both cases fail on main.
  • Two existing tests that ran a mode with no trust, to reach a later check, now use a shape that still starts.
  • Full CLI suite: all pass except seat-files.jail and seatbelt.commit-hooks, which fail the same way on main on this host. Seats package: 288 pass.

Follow-ups from the gate (Lows, not in this PR): on Windows with --unsandboxed, a public seat with a restricted network still passes and runs with the network open; agent config checks against the platform of the machine running it.

Press-held: cli/** joins Tue 11-17's cli batch.

🤖 Generated with Claude Code

https://claude.ai/code/session_01N4VWLEgKqoyJ97ffrijbor

…rce fails the seat at start (F535)

Ported from OAR's rule (D318): an option a runtime can't honour is refused
before anything opens, never silently dropped. The 11-15 audit on main
10364a0 found shapes that were accepted and then not enforced.

- hermes ran sandbox.trust=workspace bare, while the unconfined-seat guard
  read that trust as confined. It now refuses workspace at spawn, like every
  adapter but claude.
- sandboxOptionRefusal (lib/sandbox-option-refusal.js) runs beside
  providerRefusal in agent config, attach and run, so a stored or daemon
  record can't skip it. It refuses network.allow-hosts (read by no adapter),
  a restricted network under macOS Seatbelt on claude, opencode or qwen (the
  profile keeps it on), a sandbox.mode with no public or workspace trust
  (spawns bare except claude bwrap, codex and dsh), and network or filesystem
  rules on a seat with no sandbox.

Two tests that ran a mode with no trust to reach a later check now use a
shape that still starts. ADR-008 invariant 2 notes the rule.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01N4VWLEgKqoyJ97ffrijbor
@coderabbitai

coderabbitai Bot commented Nov 15, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The changes add sandbox-option refusal checks to agent configuration, attach, and run validation. They also add adapter-level refusal checks for selected Hermes, OpenCode, and Qwen configurations, with tests and documentation updates.

Changes: Sandbox option enforcement

Layer / File(s) Summary
Define sandbox refusal rules
cli/src/lib/sandbox-option-refusal.js, cli/src/lib/unconfined-seat-guard.js, cli/__tests__/sandbox-option-refusal.test.mjs, cli/__tests__/unconfined-seat-guard.test.mjs, examples/demo/demo.yaml, docs/adr/ADR-008-agent-environment-primitive.md
The checker refuses sandbox options that are not enforced in the tested adapter and environment. Tests cover unsupported and accepted configurations. The confinement helper reports whether an adapter accepts a no-trust sandbox. The demo comment and ADR describe network behavior and settings that adapters do not enforce.
Apply refusal checks in agent operations
cli/src/commands/agent.js, cli/__tests__/run-loop.test.mjs
Agent configuration updates, attach, and run validation now check sandbox options alongside provider compatibility. Run-loop tests verify refusal before client creation or adapter spawn.
Reject unsupported settings at adapter spawn
packages/seats/src/adapters/hermes.js, cli/src/lib/adapters/opencode.js, cli/src/lib/adapters/qwen.js, cli/__tests__/adapters.hermes.test.mjs, cli/__tests__/adapters.opencode.test.mjs, cli/__tests__/adapters.qwen.test.mjs
Hermes rejects workspace trust. OpenCode and Qwen reject public-seat read-outside paths. Tests verify refusal before probing or spawning.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix

Sequence Diagram(s)

sequenceDiagram
  participant AgentCommand
  participant SandboxOptionRefusal
  participant Adapter
  AgentCommand->>SandboxOptionRefusal: Validate sandbox options
  alt Unsupported option
    SandboxOptionRefusal-->>AgentCommand: Return refusal
    AgentCommand-->>AgentCommand: Stop operation
  else Options pass validation
    SandboxOptionRefusal-->>AgentCommand: Return no refusal
    AgentCommand->>Adapter: Continue operation
    Adapter->>Adapter: Apply adapter-specific spawn checks
  end
Loading
Merge Risk: Minimal · up to 769b2

This change makes the CLI refuse sandbox options that an adapter cannot enforce, instead of starting seats that silently ignore them. The refusals are covered by tests, and no concrete merge-blocking risk is identified.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: the CLI now refuses sandbox options that an adapter cannot enforce, and the seat fails at start. It matches the changeset, which adds sandboxOptionRefusal checks to ag…
Description check Passed The description covers the changeset in detail. It explains the hermes workspace-trust refusal, the new sandboxOptionRefusal rules and their call sites, the public-seat filesystem.read-outside refusal…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the main change: the CLI now refuses sandbox options that an adapter cannot enforce, and the seat fails at start. It matches the changeset, which adds sandboxOptionRefusal checks to agent config, attach and run, and makes hermes refuse workspace trust. The ticket reference and the 'fix(cli)' prefix are convention noise but do not make the title misleading.

Full details: Description check

Explanation

The description covers the changeset in detail. It explains the hermes workspace-trust refusal, the new sandboxOptionRefusal rules and their call sites, the public-seat filesystem.read-outside refusal, the ADR-008 update, the demo.yaml comment change, and the tests that were added or adjusted.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 4a79084 and 769b2b7.

Files selected for processing: 1

  • cli/src/lib/sandbox-option-refusal.js

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 0 remain after this review.

…s pass; codex refuses what its private profile ignores (F535 gate)

Gate M1: an open network policy and empty lists asked for nothing but were
refused, so the quickstart's macOS shape and examples/demo/demo.yaml would
stop starting. They pass now, and allow-hosts beside a restricted network
(which reaches no host) is left to the other rules.

Gate M2: codex runs every seat with no trust in one private profile
(workspace writable, network on), so mode read-only and network or
filesystem rules were dropped. Those are refused now; mode workspace stays.

The unconfined-seat guard's comment and the demo env's network comment say
what the adapters do.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01N4VWLEgKqoyJ97ffrijbor

@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.

Gate review by an Opus subagent at medium effort, since this is a sandbox boundary. It read 2df3b85, and the fixes are at 03a4745, which it re-checked. No High.

Medium, both fixed at 03a4745

  1. Options that were honoured got refused. An open network policy and empty lists asked for nothing, but the check counted them. So the quickstart's macOS shape (mode: none with policy: unrestricted) and examples/demo/demo.yaml (claude bwrap, restricted, allow-hosts) would have stopped starting. Both pass now. allow-hosts beside a restricted network reaches no host, so it's left to the other rules, and it's still refused wherever the restriction isn't enforced. Tests cover the quickstart shape, empty lists, demo.yaml and public bwrap opencode.
  2. The codex exemption kept options codex drops. With no trust, codex runs one private profile (workspace writable, network on), so mode read-only and network or filesystem rules did nothing. Those are refused now, and mode workspace stays. Tests pin read-only, workspace with restricted, and workspace with filesystem.

Lows

  • L1. Left as a follow-up: on Windows with --unsandboxed, a public seat with a restricted network resolves to bwrap here, so it passes, while claude runs it with no jail and the network open.
  • L2. Left as a follow-up: agent config checks against the platform of the machine running it, not the seat's host.
  • L3. Fixed: the unconfined-seat guard's comment now says what each adapter does with a mode and no trust.
  • L4. Left as is: hermes hand-copies the workspace refusal text, because packages/seats can't import cli/.
  • L5. Left as is: a dsh seat with no trust and an unsupported mode gets the generic message. dsh refuses that shape at spawn in its own words anyway.

Checked and found correct

  • These shapes are untouched: the default {trust:'public'}, public read-only opencode, legacy internal, claude workspace trust with allow, the dsh shape, and public codex.
  • Seatbelt keeps the network open on claude, opencode and qwen. Under bwrap, each adapter handles restricted itself.
  • The daemon starts seats through agent run, so it reaches performRun. Nothing re-adds sandbox options after the check, and the Windows codex opt-in strips sandbox before it. No run path skips the three call sites.
  • The four test suites this change touches pass, along with attach.test.mjs (507 tests). In the full CLI suite, the only failures are 3 in seat-files.jail and seatbelt.commit-hooks, the same as on main on this host.

Press-held: cli/** joins Tue 11-17's cli batch, after #4125 (both touch hermes.js).

GATE: PASS

Written by Lily Shen, via Claude Code.

lilyshen0722 and others added 2 commits November 15, 2026 09:31
…used on every adapter (F535 item 5)

Cofounder ruling 11-15: public agents start from nothing, and a read path
outside the workspace on a seat strangers can message is what an injected
agent would use to reach tokens. bwrap opencode and qwen bound
sandbox.filesystem.read-outside into the jail. Now the start-time check
refuses it on any public seat, legacy internal trust included, and the
opencode and qwen adapters refuse it at spawn as goose and pi already did.
Workspace trust and empty lists keep today's behaviour.

Attack case: a public bwrap opencode seat whose config asks to read
~/.commonly is refused at start, and at spawn with nothing spawned. No seat
record here or install on prod declares read-outside today.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01N4VWLEgKqoyJ97ffrijbor

@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.

Delta review of bf4efc0 (F535 item 5, Cofounder ruling 11-15: a public seat reads only its workspace). Same Opus reviewer, medium effort, since it's security. No High or Medium.

What changed

  • sandbox-option-refusal.js refuses filesystem.read-outside on every public seat at start. It checks the normalized trust, so legacy internal is included, and it applies whatever the mode, dsh included.
  • opencode and qwen now refuse it at spawn, like goose and pi. claude's public bwrap branch already did.

Checked and found correct

  • The spawn-time throws come before anything reads the path. In qwen, that's before the provider key-file roots and the bwrap wrap. In opencode, it's the top of spawnTurn, before the binds. The only readers of the path in cli/src are bwrapReadRoots and the ro-binds, and both come after the check.
  • write-outside is untouched.
  • These still run: workspace trust with read-outside, an empty list, examples/demo/demo.yaml (no trust), and the default public seat.
  • The attack case is tested at start and at both adapter spawns, with zero spawn calls: a public bwrap opencode seat asking to read ~/.commonly. The opencode test has no provider, so it can only pass through the new check.
  • No local seat record and no install on prod declares read-outside today, so no live seat changes.
  • Tests: the five suites the change touches pass. In the full CLI suite, the only failures are the two known smoke suites, the same as on main on this host.

Low, fixed at 381826b: the new tests sat between an F197 comment and its test. They've been moved.

Press-held: Tue 11-17's cli batch, after #4125.

GATE: PASS

Written by Lily Shen, via Claude Code.

This branch has not been deployed

No deployments
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