Repository navigation
feat(spawn): opt-in fail-closed worker sandbox wrapper hook - #8600
dominikbullo wants to merge 10 commits into
Conversation
|
Speaking as Kun's firstmate: thanks @dominikbullo, this matches the plan from #6170, and the relay trust-boundary write-up made the review much easier. Checked on head Contract class (my own read): opt-in. With no Waiting on you for one thing: After that, this goes to the normal full-suite gate. Because it's security-sensitive launch code, it also needs the captain's explicit word before it merges. |
|
Addressed the
Since this is a new push from a fork, the CI runs will need approving again. |
|
Speaking as Kun's firstmate: thanks @dominikbullo, I read the delta. It only removes a bind and touches docs and tests, with no workflow, network or credential changes. I approved the two new fork CI runs (44519244917 and 44519245070). The attestation binds Nothing is waiting on you right now. Next steps are on our side: CI has to finish, and our main branch is currently red for an unrelated reason, so the |
|
Speaking as Kun's firstmate: CI on This is ready for the full suite. I'm holding the |
|
Conflicts with current main are resolved at dbd3058. The no-mistakes pipeline passed review, test, document and lint on the rebased branch, and the sandbox tests (fm-sandbox-relay, fm-spawn-sandbox) pass locally. The GitHub workflows are waiting for maintainer approval (action_required), so they have not run yet. Ready for the full-ci label once main is green; happy to adjust anything. |
|
Speaking as Kun's firstmate: thanks @dominikbullo for resolving the conflicts. What I checked on Because it's a new push from a first-time fork, I approved its three CI runs (45796073452, 45796073422, 45796095585). The coverage guard, repo invariants and the no-mistakes check pass. The attestation binds One small body fix, not blocking the full suite: the regenerated description no longer has its Contract class: opt-in (no |
[Medium impact] No new blocking issue was established. Reviews (5) · Last reviewed commit: "no-mistakes(review): Probe every launch ..." · Reviewed by Greptile |
|
Merged current main (c612290) into the branch; conflicts were in Review-bot fixes folded in:
|
|
Hi @kunchenguid, a polite nudge on this one. I have now resolved conflicts with The workflows for |
|
Speaking as Kun's firstmate: thanks @dominikbullo, and thanks for keeping this conflict-free twice. Sorry for the wait on approvals. What I checked on Gates: the attestation binds One small thing: Greptile's Floods keep the host busy thread is outdated, and on my read Contract class: opt-in, unchanged. As before, this is security-sensitive launch code at the worker isolation boundary, so a green full suite takes it to Kun for an explicit merge word. That part isn't waiting on you. |
8323456 to
a350086
Compare
|
Pushed a350086 (merged current main). Fixes the two red checks from run 46140307070:
Note: this adds a required context, |
|
@kunchenguid could you approve the workflow runs for Status on
Please add |
|
Speaking as Kun's firstmate: thanks @dominikbullo, and sorry for the wait. Here's where What I checked: Why I haven't approved the runs: this head edits Still open but non-blocking: Greptile's outdated Floods keep the host busy thread. A one-line reply there would let it close. Contract class: opt-in, unchanged. VISION: unchanged from my earlier rule-by-rule read, all rules align. The shard bump is CI mechanics only. Status: waiting on Kun (captain decision), not on you. |
|
@kunchenguid the last open review thread (Greptile "Floods keep the host busy") is now resolved, so nothing is left on our side. Only your three steps remain: approve runs 46166700547, 46166700588 and 46166712141, add |
|
Speaking as Kun's firstmate: thanks @dominikbullo for closing the last thread. The head is still |
Add config/sandbox, an operator-supplied wrapper hook that runs a ship or scout omp worker inside a sandbox wrapper the operator provides. Firstmate ships no sandbox of its own. - Off when config/sandbox is absent: the launch, task record and busy extension are byte-identical to today. - config/sandbox grammar: wrapper=, enforce=off|on|strict, default=, project:<name>=, kind:ship|scout=, plus --sandbox <profile|off>. - fm-spawn wraps only the agent segment, after placeholder substitution and before the status reporter, FM_TASK_INBOX export and launch-env layers. - A profile that applies is always enforced: a missing or unnamed wrapper, a wrapper that rejects the profile, a raw launch command, a non-omp harness or backend=t3code refuses before any endpoint or record exists, and a secondmate is never sandboxed. - The task record keeps sandbox=<profile|off>; --relaunch re-applies it. - A host-side relay (fm-sandbox-relay.sh) applies the sandboxed omp busy extension's edges through fm-busy-event.sh, pinned to the task's gen, so the sandbox never needs a writable state/. - Optional --env names reach the wrapper as separate words so zsh panes work. Refs kunchenguid#6170
a350086 to
3c0508c
Compare
|
Speaking as Kun's firstmate: thanks @dominikbullo. I compared The head still edits |
|
@kunchenguid friendly nudge on this one. Nothing is left on my side: head
We have been running this sandbox shape in production for a while, so I would love to get it upstream. Thanks! |
|
Speaking as Kun's firstmate: thanks for the nudge, @dominikbullo. Nothing has changed since my last note: head FYI: #8224 also adds a 20th serial shard in |
Implements the plan agreed in #6170: an opt-in, fail-closed worker command sandbox that is a generic operator-supplied wrapper hook, not a built-in sandbox.
Closes #6170
We have been running this shape in production on our side.
What it does
config/sandbox(local, gitignored) drives it; absent, every launch is exactly what it is today.fm-spawn.shwraps only the agent segment of the launch command:<wrapper> --profile <name> <binds> --host-helper <helper> -- <agent command>.The wrapper is applied after placeholder substitution and before the status reporter, the
FM_TASK_INBOXexport, and the launch-env-allowlist layer, so those stay outside the sandbox and compose unchanged.wrapper=,enforce=off|on|strict,default=,project:<name>=,kind:ship|scout=, and--sandbox <profile|off>.enforce=onallows--sandbox offas a one-spawn waiver,strictrefuses it and any unmapped ship or scout,offis a kill switch.The spawn refuses, before any endpoint, worktree, or task record exists, and never launches the worker raw, for a missing or unnamed wrapper, a wrapper whose
--dry-runrejects the profile, an unknown profile, a raw launch command, a non-omp harness,backend=t3code(T3 starts the agent itself, so there is no pane Firstmate launches into), and a secondmate.--relaunchre-applies the profile recorded in the task meta (sandbox=<profile>, orsandbox=offfor a waiver), refuses a different profile, and accepts only--sandbox off.docs/configuration.md("Worker sandbox (config/sandbox)") owns the grammar, enforce levels, refusals, and the wrapper contract; the script headers own mechanics.Relay trust boundary
A sandboxed omp worker cannot have a writable
state/(it holds every other worker's inbox and extension), so its busy extension cannot runfm-busy-event.sh.Instead:
state/: its ownstate/<id>.sbx/events/spool, plus its own status and turn-ended files, steering inbox, and data directory.Never
state/itself and neverFM_HOME.{"state","event"}) per turn edge by rename.bin/fm-sandbox-relay.shruns on the host as the wrapper's--host-helper, validates each file, and applies it throughfm-busy-event.sh.Malformed, oversize (over 512 bytes), non-regular or symlinked, flooding, or writer-refused files are dropped and counted in a host-side log.
Only the omp harness is supported for now because the relay is omp-specific; any other harness with a resolved profile refuses rather than running unwrapped.
Tests
tests/fm-spawn-sandbox.test.sh: default launch, task record, and busy extension are byte-identical with noconfig/sandbox(compared against an inactive config, and againstorigin/mainby hand, see below); the wrap is at the one seam with only the task binds and the reporter, inbox export, and launch-env allowlist outside it; enforce levels; malformed config; each refusal (no wrapper, missing or old wrapper, unknown profile, raw launch, non-omp harness, secondmate); relaunch reusing the recorded profile, refusing a changed one, and refusing when no wrapper is configured; the sandboxed extension spooling edges and the relay applying them; and the zsh word-splitting regression (optional--env NAMEwords must reach the wrapper as separate argv words under bash and zsh, since zsh does not word-split a single unquoted expansion).tests/fm-sandbox-relay.test.sh: relay validation, ordering, gen pinning, symlink and flood handling, shutdown drain.tests/fm-backend-t3code.test.sh(t3code refusal) andtests/fm-teardown.test.sh(relay directory removal).By hand, outside the suite: running the same scout spawn fixture on
origin/mainand on this branch with noconfig/sandboxand diffing the normalized launch, pane staging, task record, and busy extension gave identical output.How it composes with the related PRs
They configure different layers and neither refuses the other.
--dry-runprobe is this seam's equivalent proof for its own profile, and the two do not overlap.Not verified
An end-to-end omp ship task inside a real wrapper ran on our side, which is the only real-runtime evidence.
Checklist
git push no-mistakeswith no steps skipped.bin/fm-lint.sh; docs follow one sentence per line and passbin/fm-doc-audience-check.sh.Intent
Implement the changes needed for firstmate to allow hooks, that we need for sandboxing.
Context: upstream issue #6170 "Add opt-in fail-closed worker command sandbox" is ready-for-pr. The agreed plan: config-driven and off when absent (default launch byte-identical, with a test proving it); refusal under enforce for a missing wrapper, an unknown profile, a backend without a pane, secondmate and t3code; the profile re-applied on --relaunch from the task meta; a generic operator-supplied wrapper hook rather than a built-in sandbox. This push resolves CI failures on the PR: the portable serial shards exceeded the 900000ms packing target because of the two new sandbox test scripts, so a 20th shard was added.
Risk Assessment
✅ Low: The round-2 fix (P1) widens the wrapper's --dry-run probe so it uses every flag the real launch passes (--ro, --rw, --rw-create, --env, --host-helper). The placeholder paths sit under the existing project dir, and a regression test rejects each flag one at a time and checks the refusal leaves no record and no launch; the rest of the branch was already reviewed and nothing new turned up.
Testing
Both sandbox suites pass (spawn seam and relay). They cover the byte-identical default launch against the 427056c golden, the enforce levels, refusals for a missing, old, unknown-profile or flag-rejecting wrapper, the secondmate refusal, the relaunch re-wrap and the relay. I also drove the real fm-spawn.sh against real bubblewrap wrappers. A wrapper that predates --env is refused up front: exit 1, no task record, no launch, and the dry-run probe carried every launch flag. A complete wrapper wraps the scout and records sandbox=strict. Inside real bwrap the worker sees its own worktree and only its own state files: no meta, no operational-inbox, no other task's files, nothing else from the host home. The t3code refusal was not re-driven. This is a CLI-only change, so there is no visual evidence.
Evidence: Live bwrap preflight and isolation transcript
Source: Live bwrap preflight and isolation transcript
Evidence: fm-spawn-sandbox suite output
Source: fm-spawn-sandbox suite output
Evidence: fm-sandbox-relay suite output
Source: fm-sandbox-relay suite output
Pipeline
Updates from git push no-mistakes
✅ **Intent** - passed
✅ No issues found.
✅ **Rebase** - passed
✅ No issues found.
✅ No issues found.
bin/fm-sandbox-lib.sh:215- The preflight probe in fm_sandbox_wrapper_ready runs the wrapper as--profile P --worktree W --host-helper true --dry-run -- true. The real launch built by spawn_sandbox_wrap (bin/fm-spawn.sh:4268-4284) also passes--ro,--rw-create,--rwand seven--env NAMEwords, and the probe never exercises any of them. The library header says--dry-run validates the profile and flags, and the refusal text says 'profile unknown or wrapper too old', so the probe is meant to catch a wrapper that is too old. Concrete case: an operator's wrapper accepts --profile and --host-helper but predates--env(added in this branch's fix rounds) or--rw-create. Preflight passes, spawn_sandbox_resolve sets SANDBOX_PROFILE, and the spawn goes on to create the worktree, endpoint and task record (sandbox=<profile>). The wrapper then rejects the unknown flag in the pane, so the worker never starts, after the documented 'refuses before any endpoint, worktree, or record exists' point. This fails closed (never raw), but the task is left half-created instead of being refused up front. The same gap applies on --relaunch, which uses the same probe. Fix at the same owner: give the dry-run one word of each bind and env flag the launch uses, for example--ro <worktree> --rw <worktree> --rw-create <worktree>/.fm-probe --env PATH. The dry-run contract says nothing is minted, so these placeholder paths are safe.🔧 Fix applied.
✅ Re-checked - no issues remain.
✅ **Test** - passed
✅ No issues found.
env -u DISABLE_AUTOUPDATER bash tests/fm-spawn-sandbox.test.sh(all pass; fish case skipped, fish not installed)bash tests/fm-sandbox-relay.test.sh(all pass)nix shell nixpkgs#ruby -c bash tests/fm-ci-workflow.test.sh(pass; ruby is not on PATH, so it came from nix)bin/fm-test-run.sh --check-coverage(FM_TEST_COVERAGE ok, serial_shards=20)bin/fm-test-run.sh --list --lane portable-serial-<k>of20for k=1..20 (sandbox suites land in shards 11 and 18)bin/fm-test-run.sh --list --lane portable-serial-1of19(refused, exit 2)live-bwrap-driver.sh: real bin/fm-spawn.sh with an operator wrapper hook built on real bubblewrap, a project mapped to strict, then a missing wrapper under enforce=on✅ No issues found.
env -u DISABLE_AUTOUPDATER bash tests/fm-spawn-sandbox.test.sh(all 15 cases ok; the fish pane shell is skipped because fish is not installed)env -u DISABLE_AUTOUPDATER bash tests/fm-sandbox-relay.test.sh(all cases ok)Live driver script: real bin/fm-spawn.sh with a disposable FM_HOME (tests/fixtures.sh helpers, fake pane and omp), config/sandboxenforce=on,project:project=strict, and a real bubblewrap wrapper that rejects --env, to check the preflight refusalSame driver with a real bubblewrap wrapper that accepts every contract flag: spawn, checksandbox=strictin the record, extract the wrapper argv from the launch text with shlex, run it under bwrap with an isolation probe in place of omp✅ **Document** - passed
✅ No issues found.
✅ No issues found.
✅ **Lint** - passed
✅ No issues found.
✅ No issues found.
✅ **Push** - passed
✅ No issues found.
✅ No issues found.