Sandlock
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.py
Why Sandlock?
Containers 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.
Architecture
Sandlock is implemented in Rust for performance and safety:
- sandlock-core: Rust library (Landlock, seccomp, supervisor, COW, pipeline)
- sandlock-cli: Rust CLI binary (
sandlock run ...) - sandlock-oci: OCI runtime shim for containerd, CRI-O, and Kubernetes (namespace-less)
- sandlock-ffi: C ABI shared library (
libsandlock_ffi.so) - Python SDK: ctypes bindings to the FFI library
- Go SDK: cgo bindings to the FFI library
See docs/architecture.md for how the pieces fit
together and how confinement is applied.
Requirements
- Linux 6.12+ (Landlock ABI v6), Rust 1.70+ (to build)
- Python 3.8+ (optional, for Python SDK)
- No root, no cgroups
| 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.
Install
From source
# Build the Rust binary and shared library
# Install Python SDK (auto-builds Rust FFI library)
&&
CLI only
Optional features
All five features (http, checkpoint, image, profiles, cow) are enabled
by default. Build with none or select the ones you need:
See Building Sandlock for feature dependencies and Rust library configuration.
Quick Start
CLI
# Basic confinement
# Interactive shell (the sandboxed command inherits the terminal)
# Resource limits + timeout
# Outbound allowlist: one host on one port
# HTTP-level ACL (method + host + path rules via transparent proxy)
# COW filesystem (writes captured, committed on success)
# Dry-run (show what files would change, then discard)
# Use a saved profile
The full option tour (GPU, network grammar, HTTPS MITM, credential
injection, port virtualization, chroot, nesting) is in
docs/cli.md.
Python API
=
# Run a command (with optional timeout in seconds)
=
assert
assert b in
# Dry-run: see what files would change, then discard
=
=
# A=added, M=modified, D=deleted
See python/README.md for the SDK guide, including
HTTP ACL, chroot mounts, port virtualization, confine(), and deferred
commit.
Rust API
use ;
use ByteSize;
let mut sandbox = builder
.fs_read.fs_read
.fs_write
.max_memory
.name
.build?;
let result = sandbox.run.await?;
assert!;
// HTTP ACL: restrict API access at the HTTP level
let mut agent = builder
.fs_read.fs_read.fs_read
.http_allow
.http_deny
.name
.build?;
let result = agent.run.await?;
// Confine the current process (Landlock filesystem only, irreversible)
let confinement = builder
.fs_read.fs_read
.fs_write
.build;
confine?;
Documentation
| Document | Contents |
|---|---|
docs/building.md |
Build commands, optional features, and minimal Rust embedding |
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/http-observer.md |
HTTP observation callbacks: requests, response status, streamed bodies |
docs/pipelines.md |
Pipelines, the XOA pattern, COW fork and map-reduce |
docs/prompt_injection.md |
Prompt injection defenses: isolation, permissions, credentials, and text inspection |
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 |
Performance
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 |
Testing
# Rust tests
# Python tests
&& &&