Go · eBPF · MIT

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.

Mohsin Khan Shaik
Mohsin Khan ShaikUpdated
2enforcement layers
Denyegress by default
TTLhard time limit
MITlicence

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.py

How it works

  1. Create a cgroup and set memory, CPU and process limits.
  2. Load eBPF programs and fill an LPM-trie policy map.
  3. Attach them to the cgroup.
  4. Start the workload straight into the cgroup with clone3(CLONE_INTO_CGROUP), so it never runs unfiltered.
  5. On exit, TTL or Ctrl-C: kill everything, remove the cgroup, detach the programs and delete the workspace.

Two enforcement layers

Socketcgroup/connect4 and sendmsg4: denied connections fail at once with EPERM instead of hanging
Packetcgroup_skb/egress: default-deny backstop for raw sockets, ICMP and unusual protocols
IPv6connect6 and sendmsg6: denied, except loopback when allowed

Policy syntax

1.1.1.1One host, any port
1.1.1.1:443One host, one port
10.0.0.0/8:5432A prefix, one port
api.example.com:443A hostname, resolved once at start

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-dns opens port 53 only to the resolvers in /etc/resolv.conf
  • Memory, CPU, process and workspace limits per sandbox
  • Runs as nobody by 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.

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.

Work with MohsinFreelance engineering, websites and advisory. Replies by email, usually within a day.