sandbox-rs
⚠️ In active development, use with caution.
A comprehensive Rust sandbox implementation that provides process isolation, resource limiting, and syscall filtering for secure program execution.
Overview
sandbox-rs is a library and CLI tool for creating lightweight, secure sandboxes on Linux systems. It combines multiple isolation mechanisms—Linux namespaces, Seccomp BPF filtering, Cgroup v2 resource limits, and filesystem isolation—into a unified, easy-to-use interface.
Features
Isolation
- Linux Namespaces: PID, IPC, network, mount, UTS, and user namespaces for complete process isolation
- Seccomp Filtering: BPF-based syscall filtering with five predefined profiles (minimal, io-heavy, compute, network, unrestricted)
- Filesystem Isolation: Overlay filesystem with copy-on-write semantics and volume mount support
Resource Management
- Memory Limits: Hard ceiling with out-of-memory enforcement
- CPU Limits: Quota-based scheduling with percentage-based controls
- Process Limits: Maximum PID restrictions per sandbox
- Runtime Monitoring: Real-time resource usage tracking
Execution
- Process Isolation: Namespace-based cloning with independent lifecycles
- Init Process: Zombie reaping and signal handling
- Root Isolation: Chroot support with credential switching (UID/GID)
Requirements
- Linux kernel 5.10+ (Cgroup v2 support required)
- Root privileges for full isolation features
- libc support for namespace and seccomp operations
Installation
Add to your Cargo.toml:
[]
= "0.1"
Usage
Library
One-shot execution:
use ;
use Duration;
Streaming output (real-time):
use ;
use Duration;
CLI
Native:
# Run program with sandbox
# List available seccomp profiles
# Check system requirements
Docker:
Run sandbox-ctl in a container without requiring root on the host machine:
# Build the Docker image
# Run sandbox-ctl with required permissions and cgroup access
# Or use docker-compose (already configured)
# Interactive mode
Note: The container requires:
- Privileged mode for Linux namespaces and seccomp filtering
- Host cgroup namespace (
--cgroupns=host) to manage cgroups - Mount of
/sys/fs/cgroupfrom host for resource limiting
Architecture
sandbox-rs is organized into modular layers:
- isolation: Namespace and Seccomp filtering mechanisms
- resources: Cgroup v2 resource limit enforcement
- execution: Process lifecycle management and initialization
- storage: Filesystem isolation with overlay and volume support
- monitoring: Process and syscall observation
- network: Network namespace configuration
- controller: Main orchestration layer coordinating all subsystems
Configuration
Memory Limits
Accepts human-readable formats:
100M- 100 megabytes1G- 1 gigabyte- Direct byte count as u64
CPU Limits
CPU quotas are enforced per sandbox:
- Percentage mode (0-100):
cpu_limit_percent(50)→ 50% of one CPU core - Raw quota mode:
cpu_quota(50000, 100000)→ 50ms per 100ms period
Seccomp Profiles
Five builtin profiles control allowed syscalls:
- minimal: Basic syscalls only (exit, read, write)
- io-heavy: Minimal + file operations (open, close, seek, stat)
- compute: IO-heavy + memory operations (mmap, brk, mprotect)
- network: Compute + socket operations (socket, bind, listen, connect)
- unrestricted: Most syscalls allowed (for debugging)
Security Considerations
This implementation provides defense-in-depth through multiple isolation layers. However:
- Sandbox escapes are possible through kernel vulnerabilities
- Not suitable for untrusted code execution without additional hardening
- Should be combined with AppArmor or SELinux for production use
- Requires ongoing kernel security updates
Testing
Tests are marked serial where required due to global state (root and cgroup manipulation).
License
See LICENSE file for details.