If you run an AI coding agent on Linux with its sandbox on, bubblewrap is probably the program doing the work. It also shows up in error messages, usually when it refuses to start. This post explains what it is, how it builds a sandbox, how two agents use it, where it stops, and how to check it on your own machine, from the project's README and manual and the agents' own docs.
What bubblewrap is
Bubblewrap was split out of Flatpak, the Linux app packaging system, which still uses it. The bubblewrap README explains why it exists: tools like Docker are built for administrators, and giving an ordinary user access to them makes it "trivial" to get a root shell. Bubblewrap is meant for unprivileged users instead.
It gets there through user namespaces, a kernel feature that lets an ordinary user set up container features for their own processes. An older setuid mode, which ran with root rights on systems without user namespaces, has been removed. The tool also sets PR_SET_NO_NEW_PRIVS, so a set-user-ID program inside cannot hand back the rights the sandbox took away.
bubblewrap is not a complete, ready-made sandbox with a specific security policy.bubblewrap, README
That sentence is the most useful thing to know about it. The README says the level of protection is "entirely determined by the arguments passed to bubblewrap", and that whatever program writes those arguments, Flatpak, an agent or your own script, is responsible for its security model.
How it builds a sandbox
Bubblewrap starts from nothing. It always creates a new mount namespace whose root is an empty, temporary filesystem the host cannot see. The caller then mounts in each folder the program should have, read-only or writable, and everything not mounted does not exist inside. This trimmed example from the README runs a shell that reuses the host's /usr and sees nothing else:
bwrap \
--ro-bind /usr /usr \
--symlink usr/lib64 /lib64 \
--proc /proc \
--dev /dev \
--unshare-pid \
--new-session \
bash
On top of the filesystem view, the caller picks which other namespaces to separate. The README lists them:
| Namespace | What the program inside sees |
|---|---|
| Mount (always) | Only the folders the caller mounted |
| User | Only its own user and group IDs |
| PID | No processes outside the sandbox |
| Network | No network, only a loopback device |
| IPC | Its own shared memory and semaphores |
| UTS | Its own hostname |
A seccomp filter, passed in by the caller, can then block system calls the namespaces do not cover. The bwrap manual adds the options that make it a sandbox rather than a different view of the same machine: --unshare-all, --clearenv to drop inherited environment variables, --die-with-parent and --new-session.
How AI coding agents use it
Claude Code. With /sandbox on, Anthropic's page on the sandboxed Bash tool says shell commands run in bubblewrap on Linux and WSL 2, in a separate network namespace "that has no connection to your network". socat relays their traffic to a proxy outside the sandbox, which checks each hostname against your allowed domains. An optional seccomp filter adds blocking of Unix domain sockets. Claude's own file and web tools, hooks and local MCP servers run outside it, and Claude can ask to rerun a failed command unsandboxed.
Codex. Its Linux sandbox README makes bubblewrap the default filesystem sandbox. It mounts the whole filesystem read-only, layers the writable folders on top, and mounts .git and .codex read-only again inside them. It separates the user and PID namespaces, separates the network when network access is restricted, and applies its own seccomp filter. It uses the first bwrap on your path and falls back to a copy it ships with.
The two agents have one thing in common: bubblewrap holds the files and cuts the network, and something else decides which hosts are allowed. On a Mac neither uses it; both use macOS Seatbelt there. Our post on Linux Landlock covers the kernel mechanism Codex used before it moved to bubblewrap.
Where it stops
The arguments are the policy. A sandbox that mounts / read-only still lets the agent read ~/.ssh and ~/.aws. Read-only keeps a file from changing; it does not keep it from leaving. Codex's view starts that way, which is why its permissions profiles can mark paths as unreadable, and why Codex's skip permissions flag, which turns the sandbox off, matters so much.
Networks are all or nothing. A network namespace has no network or the host's network. Bubblewrap has no list of hosts. Agents that need some sites and not others route traffic out through an egress proxy, and that proxy, not bubblewrap, decides where data can go.
Whatever is mounted in is reachable. The README warns that a mounted D-Bus socket can be used to run commands through systemd. Anthropic's docs give the same warning for Unix sockets with the Docker socket: allowing /var/run/docker.sock hands over the host.
The terminal and the environment. Without --new-session or a seccomp rule against it, a sandboxed program could once type commands into your terminal through the TIOCSTI call, the escape filed as CVE-2017-5226. Environment variables pass through unless the caller clears them, so a token in your shell is a token in the sandbox.
Settings that switch parts off. Claude Code's enableWeakerNestedSandbox, for use inside Docker, "considerably weakens security", in its docs' words. allowNestedUserNamespaces lets a sandboxed command make its own namespaces, and the docs say code can then end up running outside the sandbox. These are the ordinary AI agent security risks: the wrong file and the wrong host, through a gap someone opened for a good reason.
"Claude Code runs in bubblewrap."
Revision 1: its shell commands do, when the sandbox is on and the kernel lets bubblewrap start.When it will not start
Bubblewrap needs unprivileged user namespaces, and not every machine allows them. Ubuntu can restrict them through AppArmor; Anthropic's docs show the two ways to lift that, an AppArmor profile for /usr/bin/bwrap or a sysctl that lifts it for every program until reboot. Inside an unprivileged container, bubblewrap cannot mount a fresh /proc and fails with Operation not permitted. WSL 1 cannot create the namespaces at all, and Codex refuses sandboxed commands there.
What happens next matters more than the error. Claude Code's docs say that while the restriction is on, commands run without the sandbox under the regular permission flow, unless sandbox.failIfUnavailable is true, in which case Claude Code refuses to start. Codex shows a startup warning when bubblewrap cannot create user namespaces. A warning at startup is easy to scroll past, so decide which behavior you want before the day it happens.
How to check it on your machine
Which bwrap runs? Both agents take the first one on your path, so check it in the shell you start them from.
which bwrap
sysctl kernel.apparmor_restrict_unprivileged_userns
Is the restriction on? A value of 1 from the second command means Ubuntu's AppArmor rule is in force, and bubblewrap needs a profile before it can start.
Does it fail closed? For Claude Code, set sandbox.failIfUnavailable to true, so a missing sandbox stops the session instead of quietly dropping it.
Test the refusals. Ask the agent to print a file under ~/.ssh, to print its environment, and to fetch a host you did not allow. The first two tell you what the mounts and the environment hand over; the last should fail. The rules on what agentic AI security means come down to those three questions: folders, keys and hosts.
A side note on how we do it
We build Fenzi, which starts the agent in an OpenShell sandbox that sets up the same layers without bubblewrap: Landlock for folders, seccomp, a network namespace and a proxy that checks each host, with a copy of the project and placeholders instead of keys. The how it works sheet shows the pieces; bubblewrap with a proxy, or a microVM with a host list, can answer the same questions.
So, is bubblewrap enough?
Bubblewrap is a sound, small way to give an AI agent its own view of the filesystem and cut it off from the network, without root, and two major agents trust it for that on Linux. It is not a policy. The arguments decide what the agent can read, the environment decides what secrets it holds, a proxy decides where it can send, and the agent decides what happens when bubblewrap cannot start. Check all four. The bubblewrap README, its Limitations section in particular, is the best next read.