Public: anyone can read this; the crew can change it.

Sandbox floor with Landlock where bwrap cannot run. #16888

Merged opened this in answer to

Check · Review · Land · Live done — Landed and live in production.

Merged

This covers items 1–3 only in part, and item 4 (droplet and vxrail pod) is not done. Landlock now stands in for bwrap on crew runs and check steps. TCP connect confinement is not wired in.

Notes

opened this

This covers items 1–3 only in part, and item 4 (droplet and vxrail pod) is not done. Landlock now stands in for bwrap on crew runs and check steps. TCP connect confinement is not wired in. bun x tsc --noEmit and bun scripts/gate.ts --explain (32 rules) are clean. The related suites pass (landlock, the crew-sandbox* files, crew, openai-, check, contain*, cell*, spawn-argv). I did not run the full suite or any app boot.

What changed

  • Helper (src/sandbox/landlock_helper.ts): this is not a Go or Rust binary, because neither compiler is in the sandbox. It is a short-lived bun process that uses bun:ffi only to restrict itself, then execvps the command, so the forge process is never confined. It fails closed: any step the kernel refuses exits 126 and the command never runs.
  • Plan (src/sandbox/landlock.ts): pure data. It maps an ABI to the rights the kernel can enforce, strips the rest and names it, and builds the helper argv. The run record reads landlock ABI N: …; not enforced: …, udp (not covered before ABI 10).
  • Probe (landlock_probe.ts): asks the helper for the kernel's ABI. FORGE_LANDLOCK=off declines the floor.
  • Crew: sandboxAvailable() tries bwrap, then Landlock. Under Landlock the claude process itself is wrapped. It may write only its clone, run temp, install cache and Claude's own state; signals and abstract sockets are scoped. FORGE_CREW_SANDBOX=require accepts this as the floor. The run log and run record carry the ABI note.
  • Checks: under bwrap the step command is also wrapped in Landlock, inside the cell (stacked, as asked). With no cell, runStep wraps the plain sh -c in it.
  • Tests: the suite's preload sets FORGE_LANDLOCK=off. I switched the tests that gated on "bwrap works" to a new bwrapAvailable, because they would otherwise run real-sandbox tests on Landlock-only hosts.
  • Allow-list and docs: I updated one entry in scripts/spawn-argv-allow.json and added docs/features/landlock-floor.md.

Verified here: this sandbox reports ABI 6. The helper wrote inside the allowed directory, got EACCES outside it, and kill -0 1 was refused. test/landlock.test.ts checks this against the real kernel and is skipped where there is no Landlock.

Not done

  • TCP connect to the proxy port only: the plan supports it (connect: [ports], ABI 4+) but no caller sets it. Crew runs must reach the model API, and checks start servers on their own loopback ports. Bwrap's network namespace already holds egress in cells, and with Landlock alone there is no proxy port to allow.
  • Item 4, Ubuntu 24.04 droplet and vxrail pod: no access from here. Someone needs to run bun src/sandbox/landlock_helper.ts --abi on each and record the ABI.
  • No-cell checks: the install step is not wrapped; only the check step is.
  • Agent shell on Landlock-only hosts: the OpenAI runner still refuses Bash there, because it reads that policy as "not enforced". Claude Code's own sandbox is off in that mode and the process wrapper replaces it.

Reused: bwrapAvailable is the old probe body, unchanged. I extended SandboxProbe, SandboxPolicy, runStep, cellsAvailable and the existing hold path in dispatch.ts rather than adding parallel ones.

To try: on a Landlock-capable Linux kernel, run bun src/sandbox/landlock_helper.ts --abi, then bun test test/landlock.test.ts test/crew-sandbox-floor.test.ts.

Closes #16835

3 earlier comments
commented

This covers items 1–3 only in part, and item 4 (droplet and vxrail pod) is not done. Landlock now stands in for bwrap on crew runs and check steps. TCP connect confinement is not wired in. bun x tsc --noEmit and bun scripts/gate.ts --explain (32 rules) are clean. The related suites pass (landlock, the crew-sandbox* files, crew, openai-, check, contain*, cell*, spawn-argv). I did not run the full suite or any app boot.

What changed

  • Helper (src/sandbox/landlock_helper.ts): this is not a Go or Rust binary, because neither compiler is in the sandbox. It is a short-lived bun process that uses bun:ffi only to restrict itself, then execvps the command, so the forge process is never confined. It fails closed: any step the kernel refuses exits 126 and the command never runs.
  • Plan (src/sandbox/landlock.ts): pure data. It maps an ABI to the rights the kernel can enforce, strips the rest and names it, and builds the helper argv. The run record reads landlock ABI N: …; not enforced: …, udp (not covered before ABI 10).
  • Probe (landlock_probe.ts): asks the helper for the kernel's ABI. FORGE_LANDLOCK=off declines the floor.
  • Crew: sandboxAvailable() tries bwrap, then Landlock. Under Landlock the claude process itself is wrapped. It may write only its clone, run temp, install cache and Claude's own state; signals and abstract sockets are scoped. FORGE_CREW_SANDBOX=require accepts this as the floor. The run log and run record carry the ABI note.
  • Checks: under bwrap the step command is also wrapped in Landlock, inside the cell (stacked, as asked). With no cell, runStep wraps the plain sh -c in it.
  • Tests: the suite's preload sets FORGE_LANDLOCK=off. I switched the tests that gated on "bwrap works" to a new bwrapAvailable, because they would otherwise run real-sandbox tests on Landlock-only hosts.
  • Allow-list and docs: I updated one entry in scripts/spawn-argv-allow.json and added docs/features/landlock-floor.md.

Verified here: this sandbox reports ABI 6. The helper wrote inside the allowed directory, got EACCES outside it, and kill -0 1 was refused. test/landlock.test.ts checks this against the real kernel and is skipped where there is no Landlock.

Not done

  • TCP connect to the proxy port only: the plan supports it (connect: [ports], ABI 4+) but no caller sets it. Crew runs must reach the model API, and checks start servers on their own loopback ports. Bwrap's network namespace already holds egress in cells, and with Landlock alone there is no proxy port to allow.
  • Item 4, Ubuntu 24.04 droplet and vxrail pod: no access from here. Someone needs to run bun src/sandbox/landlock_helper.ts --abi on each and record the ABI.
  • No-cell checks: the install step is not wrapped; only the check step is.
  • Agent shell on Landlock-only hosts: the OpenAI runner still refuses Bash there, because it reads that policy as "not enforced". Claude Code's own sandbox is off in that mode and the process wrapper replaces it.

Reused: bwrapAvailable is the old probe body, unchanged. I extended SandboxProbe, SandboxPolicy, runStep, cellsAvailable and the existing hold path in dispatch.ts rather than adding parallel ones.

To try: on a Landlock-capable Linux kernel, run bun src/sandbox/landlock_helper.ts --abi, then bun test test/landlock.test.ts test/crew-sandbox-floor.test.ts.

commented

Gate now passes locally, and the fix is pushed.

What changed: the gate refused two as never casts in tests. test/landlock.test.ts now passes the plan directly, since the spread of landlockPlan(...) is already a LandlockPlan. test/crew-sandbox-floor.test.ts builds its plan with landlockPlan(4, { writable: [] }) instead of {} as never.

Checks: bun x tsc --noEmit is clean, the two affected test files pass (13 tests), and bun scripts/gate.ts reports no rule failures. It still prints the over-100-column comment note for src/apps/process.ts and test/helpers/preload.ts. Those files are outside this change and the nightly rewrap handles them on main. The duplicate scan hit its 8000 ms limit in the forge's log. I did not look at that further.

What I chose not to do: change any production code or the sandbox-floor behavior; only the two tests changed.

How to try it: bun test test/landlock.test.ts test/crew-sandbox-floor.test.ts.

commented

This push fixes the nine red tests from the Landlock floor change. I re-ran the seven failing test files and they pass, and tsc is clean. I did not run the full suite.

  • Docs index: docs/features/landlock-floor.md had no front matter, so the features-index tests failed. It now has topic: Your apps and a one-line row:.
  • Audits: src/sandbox/landlock_probe.ts starts a process, pipes its output and sets a kill timer, and none of the three audits listed it. It is now entered in test/spawn-sites.test.ts, test/spawn-pipes.test.ts and test/timers-named.test.ts, each with its reason.
  • Dead exports: cellFloorNote in src/apps/contain.ts had no caller, so I removed it. KNOWN_ABI in src/sandbox/landlock.ts was never read, so I removed it and its doc comment.

I did not run bun scripts/gate.ts --fix as a commit. The gate reports two over-long comment lines, in src/apps/process.ts and test/helpers/preload.ts. Neither file is part of this pull, and the gate says the nightly rewrap handles them on main.

To try it, run bun test test/spawn-sites.test.ts test/spawn-pipes.test.ts test/timers-named.test.ts test/unused-exports.test.ts test/feature-orphans.test.ts test/feature-front-matter.test.ts test/features-index-script.test.ts.

commented

This push addresses all five of @sentinel's points, with two gaps: the stacked-cell test cannot run in my sandbox, and prepareAgent has no end-to-end test. I ran the touched tests and tsc, and both pass. I did not run the full suite.

What changed

  • HIGH 1, require and the floor:
    • FORGE_CREW_SANDBOX=require no longer accepts the Landlock floor, so its runs stay held.
    • accepted() and standingOptions() in src/crew/sandbox_policy.ts now decide this, and I removed the sandboxFloor bypass in pump.
    • Only the default best-effort mode runs behind the floor.
    • The floor's note, the run log line and the check log line all say "reads are not hidden … tcp is not confined". The docs say the same.
    • I did not build a read allow-list. A real read confinement would be a larger separate change, so the floor is simply not offered under require.
  • HIGH 2, shared state: floorWritable no longer grants ~/.bun, ~/.npm, ~/.cache or CLAUDE_CONFIG_DIR.
    • The run gets HOME and CLAUDE_CONFIG_DIR under its own temp directory.
    • .credentials.json and .claude.json are copied in from the config directory the run would have used; nothing else is.
    • The copy is the run's own, so it is gone with the run's temp directory.
  • MEDIUM 3, stacked cell:
    • A cell under the floor now reveals the helper's directory as well as bun's (cellMounts). CellSpec.floor is an optional field that lets a test inject the floor.
    • test/landlock-real.test.ts runs bun and the helper inside a real openCell. It is skipped here because this sandbox has no usable bwrap or unix sockets, so the forge's check is the first place that cell test will run.
  • MEDIUM 4, tests:
    • sandboxAvailable now takes an injected bwrap probe, and test/crew-sandbox-floor.test.ts asserts without any if:
      • bwrap ok returns no floor;
      • bwrap failed with Landlock ok returns the floor;
      • both failing returns both reasons.
    • The same file tests accepted and standingOptions (the standing() logic), and that pump holds a run under require even with a floor in the options.
    • The runTier no-cell branch has a real test in test/landlock-real.test.ts; it ran and passed here, and it also checks that a write outside the check's directories is refused.
  • LOW 5:
    • I removed plan from the probe result and floorWrap, and the want parameter on probeLandlock.
    • The helper's --abi path calls abi() once.
    • A no-cell check now writes <dir>.tmp and <dir>.home instead of the machine's /tmp.

I also removed two dead exports (cellFloorNote, KNOWN_ABI).

Gaps

  • prepareAgent log line: I moved it into a small floorLine() function and tested that. There is no test that drives prepareAgent itself, because its setup is very large.
  • Landlock-only hosts: a Landlock-only host under require now behaves as it did before this pull: runs are held, not run behind the floor.

To try it, run bun test test/crew-sandbox-floor.test.ts test/landlock.test.ts test/landlock-real.test.ts. Setting FORGE_CELLS=off and unsetting FORGE_LANDLOCK runs a check behind the floor alone.

Sign in to join this conversation.

Search
↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs