feat: implement OS-level command sandboxing with bwrap#87
Merged
Conversation
Add real OS-level isolation for terminal command execution using Bubblewrap (bwrap) and seccomp. Provides filesystem isolation, capability restrictions, and network control without requiring root privileges. Features: - Detects bwrap and seccomp availability on Linux - Executes commands in isolated filesystem with read-only system paths - Mounts writable work directory for safe file operations - Graceful fallback to unsandboxed execution when bwrap unavailable - Timeout and output capture with configurable sandbox options - Integration ready with existing CommandSandbox for defense-in-depth Implementation: - OSLevelSandbox class with async/Promise-based API - Comprehensive test suite (26 test cases covering isolation, detection, errors) - All tests passing with both real bwrap sandboxing and fallback modes - Supports custom configuration for readonly paths and syscall restrictions Implements issue #69: Real command sandboxing (seccomp/bwrap) Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DLSvxucbfqMjup96KyKVyE
OSLevelSandbox was passing process.env unfiltered to both the bwrap child process and the unsandboxed fallback bash process, leaking any secret env vars (AWS keys, ANTHROPIC_API_KEY, OPENAI_API_KEY, DB passwords, etc.) into commands executed on behalf of the agent. Add filterSensitiveEnv(): strips an explicit denylist of known secret names plus a pattern-based check (SECRET/TOKEN/API_KEY/ACCESS_KEY/ PRIVATE_KEY/PASSWORD/CREDENTIAL), applied in both executeWithBwrap and executeUnsandboxed before spawning. Added failing-first TDD tests that mock child_process.spawn to assert no secret-shaped env var reaches either child process. Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DLSvxucbfqMjup96KyKVyE
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Implements OS-level isolation for terminal command execution using Bubblewrap (bwrap), with graceful fallback to unsandboxed execution when bwrap is unavailable. This PR provides filesystem isolation (read-only system paths, writable work directory) and environment variable filtering (secrets stripped from the child process environment). It does not implement seccomp syscall filtering or network isolation enforcement beyond the
--unshare-netflag already present in bwrap — those remain detection-only / best-effort in this PR.OSLevelSandboxclassbwrapwith read-only binds for/lib,/lib64,/usr,/bin, plus configurable extra readonly paths, and a bound writable work directoryAWS_SECRET_ACCESS_KEY,AWS_ACCESS_KEY_ID,DATABASE_PASSWORD,ANTHROPIC_API_KEY,OPENAI_API_KEY, and others) plus a pattern-based denylist (SECRET,TOKEN,API_KEY,ACCESS_KEY,PRIVATE_KEY,PASSWORD,CREDENTIAL) from the environment passed to both the bwrap-sandboxed process and the unsandboxed fallback process. Applied insrc/safety/os-level-sandbox.ts(filterSensitiveEnv).CommandSandboxfor defense-in-depthImplementation Details
Core Components
OSLevelSandboxclass: Manages OS-level command isolation--unshare-netwhenrestrict_netis setisSeccompSupported) but not enforced — no seccomp filter is generated or applied to the bwrap invocation in this PRfilterSensitiveEnv()denies known secret names plus a pattern-based check, applied to every spawned child process (bwrap and fallback)Testing
bwrapchild process or the unsandboxed fallbackbashchild processAcceptance Criteria
Test Plan
Run the unit tests:
```bash
pnpm run test:unit -- test/unit/safety/os-level-sandbox.test.ts
```
Expected: All 23 OSLevelSandbox tests pass, including the environment-variable-filtering tests.
Related Issues
Closes #69
🤖 Generated with Claude Code