DEV Community

İbrahim Kalaycı
İbrahim Kalaycı

Posted on

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 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 learn once on a command to trace what it needs and save a reusable sandbox.toml config.
  • 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
Enter fullscreen mode Exit fullscreen mode

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:

👉 GitHub: https://github.com/Shura5860/rust-sandbox

Top comments (3)

Collapse
 
mukherjeemahadev84tech profile image
mukherjeemahadev84-tech •

Nice project
Running without root or a daemon is a real selling point. On rsb learn, how does it handle a command that behaves differently across runs, for example one that touches a file only on a failure path? Does the generated sandbox.toml risk being too narrow and breaking the command later?

Collapse
 
shura5860 profile image
İbrahim Kalaycı •

Yeah, totally, that's the limitation of tracing a single run. If a file only gets touched on a failure path, rsb learn won't see it and the generated sandbox.toml can end up too narrow (especially with --strict).
Right now it's mostly meant as a starting point you edit by hand. Without --strict it stays in denylist mode so it's less likely to break on random error paths, and I'm planning to add a --merge option so you can combine a few different runs into one profile.

Collapse
 
mukherjeemahadev84tech profile image
mukherjeemahadev84-tech •

That makes sense. A merge option would help a lot, because one run for the normal path and another where something is made to fail should catch files that a single trace misses. Treating the generated profile as a starting point to edit by hand sounds like the safe way to use it for now.