sbx, an eBPF firewall for untrusted and AI-generated code
sbx is an open-source (MIT) Go tool that runs a command in a short-lived cgroup v2 sandbox. Network egress is denied by default and enforced in the kernel by a per-sandbox eBPF firewall, with resource limits, a hard time limit and guaranteed teardown.
The problem it solves
Agents, CI jobs and code interpreters run code nobody reviewed. The common failures are data exfiltration and resource abuse. iptables rules are host-wide and hard to scope per job, and full virtual machines are heavy for a five-minute task. sbx sits between them.
sudo sbx run --allow api.openai.com:443 --allow-dns --ttl 5m --memory 1G -- python3 agent.pyHow it works
- Create a cgroup and set memory, CPU and process limits.
- Load eBPF programs and fill an LPM-trie policy map.
- Attach them to the cgroup.
- Start the workload straight into the cgroup with
clone3(CLONE_INTO_CGROUP), so it never runs unfiltered. - On exit, TTL or Ctrl-C: kill everything, remove the cgroup, detach the programs and delete the workspace.
Two enforcement layers
Policy syntax
The policy key puts the port before the address, so one longest-prefix lookup answers "this CIDR on this port". A check is at most two lookups however many rules there are.
Features
--allow-dnsopens port 53 only to the resolvers in /etc/resolv.conf- Memory, CPU, process and workspace limits per sandbox
- Runs as
nobodyby default - JSON audit log of every denied connection or packet
- End-to-end tests against the real kernel in CI
When to use something else
- gVisor or Firecracker: choose these when you need a stronger isolation boundary for hostile code.
- Docker or Podman with network policies: choose these when you already ship images and need filesystem isolation.
- sbx: choose it for per-command, default-deny egress with an audit trail on a Linux host.
Limitations
- It is not a VM or a full container runtime.
- The filesystem is the host's, with a private tmpfs workspace and a non-root user.
- Network policy is IPv4 only; IPv6 is blocked rather than filtered.
- Hostnames are resolved once at start, so rotating CDN addresses may need a CIDR rule.
- No seccomp profile yet. A root user inside the sandbox could detach the programs, which is why the default user is nobody.
Code
GitHub repository · needs Linux 5.15+ with cgroup v2 and BTF · related: healerd, the self-healing agent
Questions and answers
What is sbx?
An open-source Go tool that runs untrusted or AI-generated code in a short-lived Linux sandbox with a per-sandbox eBPF egress firewall.
Is sbx safe enough for malicious code?
It limits network egress and resources, but it is not a VM. The filesystem is the host's and there is no seccomp profile yet, so use gVisor, Firecracker or a VM for hostile code.
How is it different from iptables?
iptables rules are host-wide. sbx attaches its own copy of the policy to one cgroup, applies it from the first instruction, and removes it when the command ends.
What does it need?
Linux 5.15 or newer with cgroup v2 and BTF, root to start, Go 1.22+, clang and libbpf headers to build.