Building a Rootless Linux Sandbox in Pure Rust — Without Docker or a Daemon
If you ever need to run untrusted scripts, test builds, or execute AI-generated code on Linux, the usual options are either spinning up a full Docker container or trusting the process on your host. I wanted something li

If you ever need to run untrusted scripts, test builds, or execute AI-generated code on Linux, the usual options are either spinning up a full Docker container or trusting the process on your host.
I wanted something lighter: a single binary and embeddable Rust library that isolates a process using Linux's built-in kernel features — no root privileges, no daemon, and no C dependencies.
That turned into rust-sandbox (rsb) (v0.1.2).
What it does
-
Folder-level access control: Choose exactly which directories a command can read or write, or run it in a temporary copy-on-write (
--cow) mode that leaves your real folder completely untouched and reports what changed on exit. - Domain-level network filtering: Keep networking off by default, or allow outbound traffic only to specific domains and ports while blocking private networks and cloud metadata IPs.
- Resource & timeout limits: Enforce timeouts, output size caps, and optional Cgroups v2 memory/CPU/PID quotas.
-
Auto-generated profiles: Run
rsb learnonce on a command to trace what it needs and save a reusablesandbox.tomlconfig. -
Embeddable everywhere: Use it as a standalone CLI, a Rust crate (
rsb-core), or via the included C and Python FFI bindings (including a warm Python worker pool for fast repeated runs).
Quick look
# Allow writing only to ./work, with no internet access
rsb run --rw ./work -- python3 untrusted.py
# Run destructively without touching the real folder
rsb ai-exec --cow ./work -- /bin/sh -c 'rm -rf ./work/*; echo test > ./work/a.txt'
# Allow HTTPS only to example.com:443
rsb run --transparent-tap --allow-domain example.com:443 -- curl -sI https://example.com
Scope & Notes
It's a Linux-only tool that shares the host kernel (namespace, Landlock, and Seccomp-BPF isolation — not a virtual machine). All of the architectural decisions and known boundaries are documented in ARCHITECTURE.md.
If you're into Rust, Linux internals, or sandboxing AI agents, feel free to check out the repo and share feedback or test it on your distro:
Originally published by Dev.to Security. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.