feat(sandbox): implement real strict mode for macOS and Linux#155
feat(sandbox): implement real strict mode for macOS and Linux#155zjshen14 wants to merge 1 commit into
Conversation
strict mode was stubbed and fell back to auto with a stderr warning. This implements it properly on both platforms: - Linux (bwrap): `buildStrictArgs` drops the blanket `--ro-bind / /` and enumerates minimum system paths (/usr, /bin, /sbin, /lib, /lib64, /etc) as read-only; $HOME is not mounted at all; --unshare-net blocks external network. Paths are only bound if they exist on the host to avoid bwrap failure on distros with merged-usr or no /lib64. - macOS (sandbox-exec): `buildStrictProfile` restricts file-read* to cwd + system binary paths; file-write* to cwd + /private/tmp; network to localhost only (no external outbound). Both constructors no longer downgrade strict→auto or emit the "not yet implemented" stderr warning. Strict-mode test blocks added to bwrap.test.ts and sandbox-exec.test.ts covering: network deny, HOME write deny, ~/.ssh read deny, CWD write allow, localhost allow. Docs updated: README.md, docs/architecture.md, and the A7 design doc status line. Closes #149 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|
Nice work on the strict-mode implementation. The approach is well thought-out:
A couple of things worth tightening before merge:
expect(result.stderr + result.stdout).toMatch(/permitted|denied/i);This doesn't assert
Cannot merge directly (touches Generated by Claude Code |
Summary
--ro-bind / /with enumerated read-only binds of minimum system paths (/usr,/bin,/sbin,/lib,/lib64,/etc);$HOMEis not mounted at all;--unshare-netblocks external network. Paths are bound conditionally on existence to handle distros with merged-usr or no/lib64.buildStrictProfilerestrictsfile-read*to cwd + system binary paths;file-write*to cwd +/private/tmp; network to localhost only (no external outbound).BwrapRunnerandSandboxExecRunnerconstructors no longer downgradestrict→autoor emit the "not yet implemented" stderr warning.bwrap.test.tsandsandbox-exec.test.tscovering: network deny, HOME write deny,~/.sshread deny, CWD write allow, localhost allow.README.md,docs/architecture.md, and the A7 design doc status line updated.Closes #149
Test plan
npm run typecheck && npm run lint && npm run format:check && npm test— all pass (553 tests, 28 skipped; the 13 new bwrap strict tests all pass; sandbox-exec strict tests correctly skip on Linux)OPENCLI_SANDBOX=strict opencli run "curl https://example.com"fails; verifyopencli run "touch ./test.txt"succeedsOPENCLI_SANDBOX=strict opencli run "curl https://example.com"fails; verifycat ~/.ssh/id_rsafails; verify writes to CWD succeedGenerated by Claude Code