sandbox-runtime-rs
OS-level sandboxing tool for enforcing filesystem and network restrictions on arbitrary processes without containerization.
Features
- Network Isolation: Proxy-based domain filtering with allowlist/denylist support
- Filesystem Restrictions: Deny-only read access, allow-only write access patterns
- Unix Socket Control: Platform-specific Unix socket restrictions
- Violation Monitoring: Real-time tracking of sandbox policy violations
- Cross-Platform: Native support for macOS and Linux
Platform Support
| Platform | Sandboxing Mechanism | Network Isolation |
|---|---|---|
| macOS | Seatbelt (sandbox-exec) |
HTTP/SOCKS5 proxy |
| Linux | Bubblewrap + seccomp | HTTP/SOCKS5 proxy + socat bridges |
Installation
Quick Install
Install the latest release with a single command:
|
This will:
- Auto-detect your OS (Linux/macOS) and architecture (x86_64/arm64)
- Download the latest release from GitHub
- Install to
/usr/local/bin(or~/.local/binif sudo is unavailable)
Building from Source
# Clone the repository
# Build in release mode
# The binary will be at target/release/srt
Installing the Binary
# Install to ~/.cargo/bin
# Or copy manually
Dependencies
macOS: No external dependencies (uses built-in sandbox-exec)
Linux:
bubblewrap(bwrap) - Required for filesystem sandboxingsocat- Required for network proxy bridgingripgrep(rg) - Recommended for dangerous file detection
# Debian/Ubuntu
# Fedora/RHEL
# Arch Linux
Quick Start
Basic Usage
Run a command with network restrictions:
# Allow only github.com and npmjs.org
Run with a custom settings file:
Run with debug logging:
Command-Line Options
srt [OPTIONS] [COMMAND]...
Options:
-d, --debug Enable debug logging
-s, --settings <PATH> Path to settings file (default: ~/.srt-settings.json)
-c <COMMAND> Run command string directly (sh -c mode)
--control-fd <FD> Read config updates from file descriptor (JSON lines protocol)
-h, --help Print help
-V, --version Print version
Arguments:
[COMMAND]... Command and arguments to run
Examples
# Run a command with default settings
# Run a shell command
# Run with custom settings
# Debug mode to see what's happening
Configuration
Configuration is loaded from ~/.srt-settings.json by default. Use the -s flag to specify a custom path.
Full Configuration Schema
Configuration Options
Network Configuration (network)
| Option | Type | Description |
|---|---|---|
allowedDomains |
string[] |
Domains allowed for network access. Supports wildcards (*.example.com). |
deniedDomains |
string[] |
Domains explicitly denied. Takes precedence over allowedDomains. |
allowLocalBinding |
boolean |
Allow binding to localhost ports. Default: false. |
httpProxyPort |
number |
External HTTP proxy port (if using external proxy). |
socksProxyPort |
number |
External SOCKS5 proxy port (if using external proxy). |
mitmProxy |
object |
MITM proxy configuration for traffic inspection. |
Unix Socket Settings (platform-specific behavior):
| Setting | macOS | Linux |
|---|---|---|
allowUnixSockets: string[] |
Allowlist of socket paths | Ignored (seccomp can't filter by path) |
allowAllUnixSockets: boolean |
Allow all sockets | Disable seccomp blocking |
Unix sockets are blocked by default on both platforms.
- macOS: Use
allowUnixSocketsto allow specific paths (e.g.,["/var/run/docker.sock"]), orallowAllUnixSockets: trueto allow all. - Linux: Blocking uses seccomp filters (x64/arm64 only). If seccomp isn't available, sockets are unrestricted and a warning is shown. Use
allowAllUnixSockets: trueto explicitly disable blocking.
Filesystem Configuration (filesystem)
| Option | Type | Description |
|---|---|---|
denyRead |
string[] |
Paths/patterns denied for reading. Supports globs. |
allowWrite |
string[] |
Paths allowed for writing. Default: deny all writes. |
denyWrite |
string[] |
Paths denied for writing. Overrides allowWrite. |
allowGitConfig |
boolean |
Allow writes to .git/config. Default: false. |
Other Options
| Option | Type | Description |
|---|---|---|
ignoreViolations |
object |
Map of command patterns to violation regexes to ignore. |
enableWeakerNestedSandbox |
boolean |
Enable weaker nested sandbox mode. |
ripgrep |
object |
Ripgrep configuration for dangerous file discovery. |
mandatoryDenySearchDepth |
number |
Search depth for mandatory deny discovery (Linux). Default: 3. |
allowPty |
boolean |
Allow pseudo-terminal access (macOS only). Default: false. |
seccomp |
object |
Custom seccomp filter configuration (Linux only). |
Example Configurations
Development Environment:
Restrictive Production:
Library Usage
Use sandbox-runtime as a Rust library in your project:
[]
= { = "../sandbox-runtime-rs" }
= { = "1", = ["full"] }
use *;
use ;
async
Key Types
SandboxManager- Main entry point for sandbox operationsSandboxRuntimeConfig- Complete configuration structureNetworkConfig- Network restriction settingsFilesystemConfig- Filesystem restriction settingsSandboxViolationStore- In-memory violation tracking
Architecture
sandbox-runtime-rs/
├── src/
│ ├── main.rs # CLI entry point
│ ├── lib.rs # Library exports
│ ├── cli.rs # Command-line argument parsing
│ ├── error.rs # Error types
│ ├── config/ # Configuration handling
│ │ ├── mod.rs
│ │ ├── schema.rs # Config types and validation
│ │ └── loader.rs # File loading
│ ├── manager/ # Sandbox orchestration
│ │ ├── mod.rs # SandboxManager
│ │ ├── state.rs # Internal state
│ │ ├── network.rs # Proxy initialization
│ │ └── filesystem.rs # FS config processing
│ ├── proxy/ # Network proxy servers
│ │ ├── mod.rs
│ │ ├── filter.rs # Domain filtering logic
│ │ ├── http.rs # HTTP/HTTPS proxy
│ │ └── socks5.rs # SOCKS5 proxy
│ ├── sandbox/ # Platform-specific sandboxing
│ │ ├── mod.rs
│ │ ├── macos/ # macOS Seatbelt implementation
│ │ │ ├── mod.rs
│ │ │ ├── profile.rs # Seatbelt profile generation
│ │ │ ├── wrapper.rs # Command wrapping
│ │ │ ├── glob.rs # Glob-to-regex conversion
│ │ │ └── monitor.rs # Log monitoring
│ │ └── linux/ # Linux bubblewrap implementation
│ │ ├── mod.rs
│ │ ├── bwrap.rs # Bubblewrap command generation
│ │ ├── filesystem.rs # Bind mount generation
│ │ ├── bridge.rs # Socat bridge management
│ │ └── seccomp.rs # Seccomp filter handling
│ ├── utils/ # Utility functions
│ │ ├── mod.rs
│ │ ├── platform.rs # Platform detection
│ │ ├── path.rs # Path normalization
│ │ ├── shell.rs # Shell quoting
│ │ ├── ripgrep.rs # Ripgrep integration
│ │ └── debug.rs # Debug logging
│ └── violation/ # Violation tracking
│ ├── mod.rs
│ └── store.rs # In-memory violation store
└── Cargo.toml
How It Works
Network Isolation
- Proxy-Based Filtering: The sandbox starts HTTP and SOCKS5 proxy servers on localhost
- Environment Variables: Commands run with
http_proxy,https_proxy, andALL_PROXYset - Domain Filtering: Each connection is checked against allowed/denied domain lists
- MITM Support: Optional routing through a MITM proxy for inspection
┌─────────────────────────────────────────────────────────────┐
│ Sandboxed Process │
│ ┌─────────────────────────────────────────────────────────┐ │
│ │ curl https://api.github.com │ │
│ └───────────────────────┬─────────────────────────────────┘ │
│ │ HTTP_PROXY=localhost:3128 │
└──────────────────────────┼───────────────────────────────────┘
│
▼
┌──────────────────────────────┐
│ HTTP/SOCKS5 Proxy │
│ ┌────────────────────────┐ │
│ │ Domain Filter │ │
│ │ ┌──────────────────┐ │ │
│ │ │ allowed: ✓ │ │ │
│ │ │ denied: ✗ │ │ │
│ │ │ mitm: → MITM │ │ │
│ │ └──────────────────┘ │ │
│ └────────────────────────┘ │
└──────────────────────────────┘
│
▼ (if allowed)
Internet
Filesystem Isolation
macOS (Seatbelt):
- Generates a Seatbelt profile (
.sbfile) with SBPL rules - Uses
sandbox-exec -f profile.sb commandto run - Supports glob patterns for path matching
Linux (Bubblewrap):
- Creates isolated filesystem namespace with
bwrap - Mounts root as read-only, overlays writable paths
- Uses seccomp to block unauthorized Unix socket creation
Mandatory Deny Paths
The following files/directories are always protected from writes:
Dangerous Files:
.gitconfig,.bashrc,.bash_profile,.profile.zshrc,.zprofile,.zshenv,.zlogin.npmrc,.yarnrc,.yarnrc.yml.mcp.json,.mcp-settings.json
Dangerous Directories:
.git/hooks,.git.vscode,.idea.claude/commands
Security Considerations
Limitations
- Proxy Bypass: Sandboxed processes that don't respect proxy environment variables may bypass network filtering
- Root Access: The sandbox cannot protect against processes running as root
- Kernel Exploits: Sandbox escapes via kernel vulnerabilities are possible
- Unix Sockets (Linux): Without seccomp, processes may create Unix sockets to bypass network restrictions
Best Practices
- Always specify an explicit
allowedDomainslist rather than relying ondeniedDomainsalone - Use the most restrictive
allowWritepaths possible - Enable seccomp on Linux when available
- Review violation logs regularly
- Keep the sandbox runtime updated
Development
Building
# Debug build
# Release build
# Run tests
# Run with logging
RUST_LOG=debug
Testing
# Run all tests
# Run specific test module
# Run with output
Code Structure
- Platform-specific code uses
#[cfg(target_os = "...")]attributes - Configuration uses
serdefor JSON serialization - Async runtime is
tokio - Error handling uses
thiserrorandanyhow
Acknowledgments
This project is a Rust port of sandbox-runtime, the original TypeScript implementation by Anthropic. The core architecture, sandboxing approach, and configuration schema are derived from that project.
License
MIT License - see LICENSE for details.