symcc

Research: can symcc start each worker in a sandbox that only lets it write inside its own folder? #

Kept from task T-357 (3 tries). This note holds the final, combined answer.

The question #

Can symcc start each worker so that it can only write inside its own worktree folder?

Short answer #

On macOS and Linux (including WSL2), yes. Both were tested. On native Windows, not yet in a way to trust: the only tool that does it there is an "alpha" and needs an admin install, and it could not be tested. Claude Code's own sandbox does not work on native Windows either. Its docs say: "On native Windows, Claude Code runs commands unsandboxed."

The way that works (called "(A)"): symcc's tool.call hook rewrites each worker's Bash command so it runs inside an operating-system sandbox. Only the worker's own folder (plus a few git and temp paths) can be written.

1. Claude Code's own Bash sandbox (why it doesn't fit as it is) #

Sources: https://code.claude.com/docs/en/sandboxing, and Claude Code 2.1.319 on a Mac.

What it limits:

How to turn it on:

Operating systems (docs):

Why it doesn't fit symcc:

2. Way (A) on macOS: tested end to end #

Setup:

on('tool.call', async ($, e, next) => {
  if (e.tool !== 'Bash' || !e.agentId) return next(e)
  return next({ ...e, command: `/usr/bin/sandbox-exec -f ${PROFILE} /bin/zsh -c ${sq(e.command)}` })
})

The profile allowed writes only in:

Refused (operation not permitted):

Worked:

symcc's own suite (claude plugin test .) passed 865 of 865 under a profile that allowed only the folder plus $TMPDIR.

Side effects:

The permission check sees the wrapped command:

When Claude Code's own sandbox is also on: the wrapped command fails, with exit 71 and sandbox-exec: sandbox_apply: Operation not permitted, because one Seatbelt sandbox can't be nested in another. $.settings.read({key:'sandbox'}) shows enabled:true, so symcc can detect this and skip wrapping.

3. Linux: tested #

Setup:

bwrap --ro-bind / / --dev /dev --proc /proc --unshare-pid \
  --bind $W $W --bind $G/objects $G/objects --bind $G/worktrees/w1 $G/worktrees/w1 \
  --bind $G/refs/heads/symcc $G/refs/heads/symcc --bind $G/logs/refs/heads/symcc $G/logs/refs/heads/symcc \
  --tmpfs /tmp --chdir $W -- /bin/bash -c "<command>"

Results:

Worker commandResult
pwdthe worktree
write in the worktreeworks
echo x > ../../../a.txtRead-only file system
write to a base64-built path into mainRead-only file system
symlink to main, then writerefused
node writeFileSync into mainrefused (child processes are covered)
echo hi > ~/x.txtrefused
git add && git commitworks and lands on symcc/w1. Prints the same harmless packed-refs.lock message
git -C <root> branch -f other HEADrefused (cannot lock ref)
git update-ref refs/heads/other HEADrefused
mktemp, touch /tmp/x, node os.tmpdir()work (a private /tmp per command)
psworks (unlike macOS)
git branch -f symcc/w2 HEADworked: a worker could move another symcc task's branch

Afterwards, a.txt and main in the main checkout were unchanged.

The Linux gap, and why it exists: bubblewrap can only open existing files and folders for writing. Git writes a new <branch>.lock file next to the ref, and that file doesn't exist beforehand. So symcc must open the whole .git/refs/heads/symcc/ folder, which also covers the other workers' branches. main and other non-symcc branches stay safe. macOS has no such gap, because there the profile can name the not-yet-existing lock file (and in the srt test below, symcc/w2 was refused). This is a smaller hole than today's, and the merge-time scope check already runs per branch. Still, it is a real difference.

Linux catches (from the docs and the srt README; not all tested):

4. One tool for all three systems: Anthropic's srt #

Source: https://github.com/anthropic-experimental/sandbox-runtime (npm @anthropic-ai/sandbox-runtime, Apache-2.0, labelled "early research preview"). Version 0.0.83 was tested.

What it is:

Tested on macOS (allowWrite = worktree, .git/objects, .git/worktrees/w1, the literal refs/heads/symcc/w1 and its .lock, its ref log, and packed-refs.lock):

Tested on Linux, as a normal user, same settings:

Windows (from the README only, not tested):

What srt costs compared with calling sandbox-exec/bwrap directly:

What it gives:

5. The lead and the owner's own session #

Only Bash calls whose agentId is a live symcc worker get wrapped. The main session's Bash ran unwrapped in the test, so the lead and the owner are not limited to one folder. The real hook should check symcc's workers map, not "any subagent".

6. Way (B): a separate claude -p per worker #

Tested: claude -p --settings '{"sandbox":{"enabled":true,...}}' in a worktree. Commits went through, and writes to main were refused.

What symcc would lose: everything tied to $.agent.spawn:

It is also no better on native Windows, because Claude Code's sandbox doesn't run there. This belongs to the planned standalone-runner work, not to this question.

7. Fallback for systems with no sandbox (native Windows, WSL1, no bwrap, or Claude Code's sandbox already on) #

Around each worker Bash call in tool.call, compare git -C <root> status --porcelain and git for-each-ref before and after. If anything changed, warn the owner.

Limits:

What was not checked #

Recommendation #

Build (A) with a small "sandbox backend" chosen by OS. Start with macOS and Linux, and use the watcher fallback everywhere else.

  1. Choosing the backend:
    • On darwin, call /usr/bin/sandbox-exec with a generated profile (about 2 to 3 days).
    • On linux (including WSL2), call bwrap with the bind list from section 3 (about 1 to 2 more days). Bind .git/refs/heads/symcc and .git/logs/refs/heads/symcc (create them first), and give each command a private /tmp.
    • If bwrap is missing or fails a quick start-up test, fall back.
    • Native Windows, or Claude Code's sandbox on: don't wrap. Run the watcher from section 7 and tell the owner once that workers are not sandboxed on this machine.
  2. Direct tools or srt: call sandbox-exec/bwrap directly for now: no new dependency, no beta tool, and every path stays under symcc's control. Keep srt as the later option if native Windows matters. Its Windows support is alpha, needs an admin install, and leaves lasting access rules on folders. Test it on a real Windows machine before relying on it.
  3. Permission checks:
    • Run bashOutsideFolder on the original command in tool.call.
    • Answer tool.check on the original command, with relative paths made absolute against the worktree.
    • Tell workers that cd doesn't carry over, and that on macOS ps is unavailable.

Test plan #

Unit tests (tests/):

Live run on a throwaway project, on macOS and on Linux (a VM or podman --privileged; also a normal Ubuntu 24.04 VM, for AppArmor). A worker must be refused for:

It must succeed for git commit, the board's test command and mktemp.

Afterwards the main folder and its refs must be unchanged. Also check that the lead's Bash is not wrapped, that stop, ask_owner, token counts and the hand-back still work, and that a Bash(npm test:*) rule still works.

On Windows: check that the warning appears and the watcher reports a change to the main folder.

How it was found #

Three tries. Try 1 read the Claude Code sandbox docs and tested way (B). Try 2 tested way (A) on macOS in a real Claude Code session. Try 3 tested bubblewrap on Linux in a podman container and tested srt on macOS and Linux; Windows was read from the README only. No project files were changed by the research.