最轻量级的 AI 沙箱。基于进程的 Linux 沙箱,无容器、无虚拟机、无特权、无提示注入
Lightweight process sandbox for Linux. Confines untrusted code using Landlock (filesystem + network + IPC), seccomp-bpf (syscall filtering), and seccomp user notification (resource limits, IP enforcement, /proc virtualization). No root, no cgroups, no containers.
sandlock run -w /tmp -r /usr -r /lib -m 512M -- python3 untrusted.pyContainers and VMs are powerful but heavy. Sandlock targets the gap: strict confinement without image builds or root privileges. Built-in COW filesystem protects your working directory automatically.
| Feature | Sandlock | Container | MicroVM (Firecracker) |
|---|---|---|---|
| Root required | No | Yes* | Yes (KVM) |
| Image build | No | Yes | Yes |
| Startup time | ~5 ms | ~200 ms | ~100 ms |
| Kernel | Shared | Shared | Separate guest |
| Filesystem isolation | Landlock + seccomp COW | Overlay | Block-level |
| Network isolation | Landlock + seccomp notif | Network namespace | TAP device |
| HTTP-level ACL | Method + host + path rules | N/A | N/A |
| Syscall filtering | seccomp-bpf | seccomp | N/A |
| Resource limits | seccomp notif + SIGSTOP | cgroup v2 | VM config |
* Rootless containers exist but require user namespace support and /etc/subuid configuration.
Sandlock is implemented in Rust for performance and safety:
sandlock run ...)libsandlock_ffi.so)See docs/architecture.md for how the pieces fit
together and how confinement is applied.
| Feature | Minimum kernel |
|---|---|
| seccomp user notification | 5.6 |
| Landlock filesystem rules | 5.13 |
| Landlock TCP port rules | 6.7 (ABI v4) |
| Landlock IPC scoping | 6.12 (ABI v6) |
Protections can be selectively waived per-policy when needed; see
docs/sandbox-reference.md#protection-opt-out.
# Build the Rust binary and shared library
cargo build --release
# Install Python SDK (auto-builds Rust FFI library)
cd python && pip install -e .cargo install --path crates/sandlock-cli…The full option tour (GPU, network grammar, HTTPS MITM, credential
injection, port virtualization, chroot, nesting) is in
docs/cli.md.
…See python/README.md for the SDK guide, including
HTTP ACL, chroot mounts, port virtualization, confine(), and deferred
commit.
…| Document | Contents |
|---|---|
docs/cli.md |
Every sandlock run option by example, profiles, ps / inspect / kill |
docs/sandbox-reference.md |
Every Sandbox field, default, and TOML key; credentials; protection opt-out |
docs/network.md |
Endpoint grammar, protocol gating, HTTP interception, bind rules, port virtualization |
docs/policy-fn.md |
Dynamic policy callbacks: events, verdicts, context methods, TOCTOU guarantees |
docs/pipelines.md |
Pipelines, the XOA pattern, COW fork and map-reduce |
docs/architecture.md |
Crate layout, confinement sequence, supervisor handlers, COW filesystem |
docs/learn.md |
sandlock learn: generate a profile from an observed run |
docs/extension-handlers.md |
Custom seccomp-notification handlers (Rust and C ABI) |
docs/python-handlers.md |
Custom handlers from Python |
python/README.md |
Python SDK guide |
go/README.md |
Go SDK guide |
crates/sandlock-oci/README.md |
OCI runtime shim |
Benchmarked on a typical Linux workstation:
| Workload | Bare metal | Sandlock | Docker | Sandlock overhead |
|---|---|---|---|---|
/bin/echo startup |
2 ms | 7 ms | 307 ms | 5 ms (44x faster than Docker) |
| Redis SET (100K ops) | 82K rps | 80K rps | 52K rps | 97.1% of bare metal |
| Redis GET (100K ops) | 79K rps | 77K rps | 53K rps | 97.1% of bare metal |
| Redis p99 latency | 0.5 ms | 0.6 ms | 1.5 ms | ~2.5x lower than Docker |
| COW fork ×1000 | n/a | 530 ms | n/a | 530μs/fork, ~1,900 forks/sec |
# Rust tests
cargo test --release
# Python tests
cd python && pip install -e . && pytest tests/暂无开放 Issues,或尚未同步最近议题。