Skip to content

feat(sandbox): Seatbelt backend so sandbox=workspace works on macOS - #524

Merged
mrnasil merged 3 commits into
mainfrom
feat/macos-seatbelt-sandbox
Dec 1, 2026
Merged

mrnasil merged 3 commits into
mainfrom
feat/macos-seatbelt-sandbox

Conversation

@mrnasil

@mrnasil mrnasil commented Nov 29, 2026

Copy link
Copy Markdown
Member

What

sandbox = "workspace" (the default) only had a backend on Linux. On macOS every shell command ran on the host with a one-time warning. This adds a Seatbelt backend: /usr/bin/sandbox-exec -p <profile> bash -c <command>.

The profile allows everything, then denies file writes outside:

  • the project directory (canonical path),
  • the temp directories (/private/tmp, /private/var/folders),
  • a few device nodes (/dev/null, /dev/tty, /dev/ttys*, /dev/fd, …),
  • the toolchain caches the bubblewrap backend already binds (~/.cargo, ~/.npm, …) plus ~/Library/Caches.

sandbox_network = false adds (deny network*).

Differences from Linux, documented in the guide: there is no private /tmp; the host temp directories stay writable.

Windows still has no backend and follows sandbox_fallback. Its message no longer says "Linux-only".

Internals

  • prepare_with / describe_backend_with take the workspace Backend instead of a bwrap_available bool, so tests reach every branch on any host.
  • whycodes doctor prints a seatbelt: line on macOS.

Verification

  • cargo test -p whycodes-sandbox: green on Windows and on Linux (WSL, with bwrap, live tests included).
  • Linux line coverage of crates/sandbox/src: 0 missed lines in every file (LLVM_COV_FLAGS=-skip-expansions cargo llvm-cov -p whycodes-sandbox).
  • cargo check -p whycodes-sandbox --target aarch64-apple-darwin --tests: compiles.
  • clippy, fmt and the budget scripts: clean.

Not verified yet — do not merge before this

The profile has not run on a real Mac. The Mac test host was unreachable and the hosted macOS CI jobs are off (CI_MULTI_OS). crates/sandbox/tests/live_macos.rs holds the checks to run there:

cargo test -p whycodes-sandbox --test live_macos

It checks that the project and /tmp are writable, git init works, a write to $HOME fails, and TCP fails with the network off. A wrong profile would break bash for every macOS user on the default config, so this stays a draft until that run is green.

🤖 Generated with Claude Code

mrnasil and others added 3 commits November 30, 2026 00:20
macOS ran every shell command on the host: the workspace sandbox was
bubblewrap only, so the default `sandbox = "workspace"` fell back with a
warning there.

`sandbox-exec` (part of macOS) now wraps `bash -c` with a profile that
allows everything, then denies file writes outside the project, the temp
directories, a few device nodes and the toolchain caches (the bubblewrap
list plus ~/Library/Caches). `sandbox_network = false` adds
`deny network*`. There is no private /tmp as on Linux; the docs say so.

`prepare_with` takes the workspace backend instead of a bwrap bool, so
tests reach every branch on any host. Windows still has no backend and
follows `sandbox_fallback`; its message no longer says "Linux-only".

Co-Authored-By: Claude Fable 5.2 <[email protected]>
…ny backend

On macOS the workspace backend is Seatbelt, so backend_available() is true
without bwrap and the old assertion failed there.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
@mrnasil
mrnasil marked this pull request as ready for review December 1, 2026 16:20
@mrnasil
mrnasil merged commit cf1a657 into main Dec 1, 2026
7 checks passed
@mrnasil
mrnasil deleted the feat/macos-seatbelt-sandbox branch December 1, 2026 16:21
@mrnasil mrnasil mentioned this pull request Dec 3, 2026
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