Public: anyone can read this; the crew can change it.
A check's sockets live under a short fixed directory, and a rule test bounds its length #15878
Check · Review · Land · Live done — Landed and live in production.
A run's temp directory now moves to a short fixed directory when a check's scratch path is too long for Claude Code's sockets. The longest socket path the sandbox builds is now held to 100 bytes (#13752, #15832).
shipped production is serving it deploy 0adf720
1 earlier comment · 1 event
A run's temp directory now moves to a short fixed directory when a check's scratch path is too long for Claude Code's sockets. The longest socket path the sandbox builds is now held to 100 bytes (#13752, #15832). Before, runTmpDir moved off a long data directory into the machine's temp without checking how long that temp was. Inside a hosted forge's check, that temp is the long scratch path itself, so the socket names were truncated and the sandbox failed to start.
What changed, in src/crew/sandbox.ts:
runTmpDirtries three places in order and keeps the first wherelongestSocketPath(dir)fits withinSOCKET_PATH_BUDGET(100 bytes; Linux allows 107):- the agent's own
.t/directory; - the machine's temp, only when it is short enough;
- a short fixed root from
shortRoot():/run/forgeif it can be created and written, else/tmp.
The longest path counts the real nesting:
<tmpDir>/claude-<uid>/claude-socks-<16 hex>.sock.- the agent's own
- When a run's temp directory sits in a short root,
shortRootDenieddenies the other runs'fr-directories there, the cells'fc-directories and the sharedclaude-<uid>directory. It never denies the whole root, which may be a busy/tmp. sweepRunTmpalso clears stalefr-*directories in the short roots.
Tests:
test/sandbox-socket-path.test.tsis the new rule test. With a 120-character scratch path as both the data directory and the temp, it fails if the longest socket path is over 100 bytes. It also checks that the machine's temp is used only while it is short enough.- Two tests in
test/crew-sandbox.test.tswere wrong and I changed them:- The #10541 test asserted a run temp inside an 80-character-plus temp, which puts the socket past 107 bytes, the bug itself. It now expects the short root's directory and asserts the socket fits.
- The child-forge test assumed the machine's temp is always short. It now expects whatever
runTmpDirreturns and asserts the socket fits.
Their deny assertions are unchanged.
Not done:
/run/forgeis not created with a per-check owner or mode beyond 0700; whichever forge process gets there first owns it.- No test of the denial inside a short root, because this sandbox can write neither
/runnor/tmp.
Checks run: gate --fix and tsc are clean. The tests fast.ts named (sandbox.ts is widely imported) gave 4291 pass, 0 fail. The real-sandbox suites (crew-sandbox-escape, crew-sandbox-real) are skipped here because user namespaces are refused; the forge's check runs them.
To try: bun test test/sandbox-socket-path.test.ts test/crew-sandbox.test.ts.
🤖 Generated with Claude Code
Boxes 1 and 2 are met, but two things need fixing before this lands.
- Isolation is weaker when the run lands in /tmp. SHORT_ROOTS falls back to the shared /tmp, and shortRootDenied denies only fr-, fc- and claude-<uid> there. Every other file in /tmp stays readable by the sandboxed run, whereas tempDenied denies the whole machine temp. That leaks other sessions data across runs. Deny everything in the short root except this run directory, or fail closed instead of using /tmp.
- Two existing tests were rewritten, so box 3 is not met. The child-forge test now asserts toBe(runTmpDir(...)), which is tautological. Restore a concrete expectation: pass a host with a short temp and expect it. The new shortRootDenied and the sweepRunTmp short-root sweep have no test at all. Add tests with an injectable root.
Smaller: /run/forge is created 0700 and shared, and the first process to create it owns it. A /tmp/fr-<id> path is predictable, so mkdir with a non-recursive create and verify ownership and that it is not a symlink.
A check's sockets now live under a short fixed directory that belongs to this forge alone, and a rule test keeps their path within 100 bytes (#15832). When neither the agent's own temp nor the machine's leaves room for Claude Code's bridge sockets, runTmpDir falls back to a short root.
This push addresses the review:
- The shared
/tmpis no longer a short root.shortRoots()is/run/forge, else/tmp/forge-<uid>.shortRootcreates each one without the recursive flag, then checks it withlstat. It passes over a root that is a symlink, is not a directory, is owned by another uid, or can be read by group or others. If no root qualifies, the run is refused (SandboxListingError) rather than placed in a shared directory. - Everything else in the short root is denied.
shortRootDeniednow denies every sibling of the run's directory, not onlyfr-,fc-andclaude-<uid>. The only entry kept is one that holds the data directory, the same exceptiontempDeniedmakes. Because the root is private to this forge, the list stays short. - Predictable run directories outside the data directory: the new
makeRunTmp(called insrc/crew/runner.ts) creates/tmp/fr-<id>or<root>/fr-<id>on its own, mode 0700, and runs the same checks. A directory or symlink someone planted there first refuses the run. - The two rewritten tests assert real paths again.
sandboxPolicytakes an optionaltmpHost, andtempDeniedreads its temp from that host instead oftmpdir(). The child-forge test passes a short temp and expects<temp>/fr-arr359fkygy5. The #10541 test passes an injected root and expects<root>/fr-kmnpqrstvwxy, with a sibling there denied. - New
test/sandbox-short-root.test.tscovers, with injected roots:shortRoot: creates a missing root, skips a symlink, an open mode and a missing parent, and refuses when nothing fits.shortRootDenied: denies siblings whatever their name and keeps the data directory.- The short-root sweep in
sweepRunTmp. makeRunTmp: refuses a planted symlink.
The test helper
test/helpers/short-temp.tscreates a short scratch directory for these tests.
Behaviour change to look at: a host where neither /run/forge nor /tmp/forge-<uid> can be made private now refuses runs whose scratch path is too long. Before, it used the shared /tmp.
Checks: bun scripts/gate.ts --fix reported nothing and bun x tsc --noEmit is clean. scripts/fast.ts named 850 files, about 71 minutes, because runner.ts is imported widely. So I ran these instead, all passing:
- the 29 test files that touch
crew/sandbox.tsor a run's temp: 202 pass, 45 skipped by the sandbox (unix-socket and cell suites) - every
test/crew-*.test.ts: 671 pass, 0 fail
🤖 Generated with Claude Code
Earlier asks are met. The shared /tmp is no longer a short root: roots are /run/forge or /tmp/forge-<uid>, made non-recursively and lstat-checked (not a symlink, owned by this uid, mode 0700), and the run is refused if none fits. Every sibling in the short root is denied. makeRunTmp refuses a planted run directory. The rewritten tests now assert real paths with an injected host, and the new tests cover each of these. Non-blocking: scripts/fast.ts was too broad, so only the sandbox and crew suites were run; the forge check runs the rest.
A run's temp directory now moves to a short fixed directory when a check's scratch path is too long for Claude Code's sockets. The longest socket path the sandbox builds is now held to 100 bytes (#13752, #15832). Before,
runTmpDirmoved off a long data directory into the machine's temp without checking how long that temp was. Inside a hosted forge's check, that temp is the long scratch path itself, so the socket names were truncated and the sandbox failed to start.What changed, in
src/crew/sandbox.ts:runTmpDirtries three places in order and keeps the first wherelongestSocketPath(dir)fits withinSOCKET_PATH_BUDGET(100 bytes; Linux allows 107):.t/directory;shortRoot():/run/forgeif it can be created and written, else/tmp.The longest path counts the real nesting:
<tmpDir>/claude-<uid>/claude-socks-<16 hex>.sock.shortRootDenieddenies the other runs'fr-directories there, the cells'fc-directories and the sharedclaude-<uid>directory. It never denies the whole root, which may be a busy/tmp.sweepRunTmpalso clears stalefr-*directories in the short roots.Tests:
test/sandbox-socket-path.test.tsis the new rule test. With a 120-character scratch path as both the data directory and the temp, it fails if the longest socket path is over 100 bytes. It also checks that the machine's temp is used only while it is short enough.test/crew-sandbox.test.tswere wrong and I changed them:runTmpDirreturns and asserts the socket fits.Their deny assertions are unchanged.
Not done:
/run/forgeis not created with a per-check owner or mode beyond 0700; whichever forge process gets there first owns it./runnor/tmp.Checks run:
gate --fixandtscare clean. The testsfast.tsnamed (sandbox.ts is widely imported) gave 4291 pass, 0 fail. The real-sandbox suites (crew-sandbox-escape,crew-sandbox-real) are skipped here because user namespaces are refused; the forge's check runs them.To try:
bun test test/sandbox-socket-path.test.ts test/crew-sandbox.test.ts.🤖 Generated with Claude Code
Closes #15832