Bubblewrap (command name bwrap) is a small, low-level sandboxing tool for Linux that starts a program inside new kernel namespaces and gives it a filesystem view assembled entirely from explicit bind mounts, so the program sees only what the caller chooses to expose. In Linux security, it occupies the space between a plain chroot and a full container runtime: it needs no daemon and no root privileges on most modern systems, and it is the isolation engine behind Flatpak, several browser engine sandboxes and many developer tools.
Bubblewrap deliberately ships no built-in security policy. It is a construction kit: the calling application or administrator decides which directories are visible, which namespaces are unshared and which system calls are filtered. That design keeps the tool auditable, but it also means that a sandbox built with bwrap is only as strong as its command line.
How Bubblewrap builds a sandbox
Bubblewrap builds a sandbox by creating an empty mount namespace on a tmpfs root and then populating it, step by step, with the paths named in its arguments. Nothing from the host filesystem is visible unless an option such as --ro-bind or --bind places it there, which reverses the usual container approach of starting from a full image and hiding parts of it.
The sequence is short and predictable. Bubblewrap calls clone() with the requested namespace flags, maps the calling user to a user ID inside a user namespace, mounts the new root, applies each bind, --proc, --dev and --tmpfs instruction in order, calls pivot_root() and finally executes the target program. Before the exec, it sets PR_SET_NO_NEW_PRIVS, so setuid binaries inside the sandbox cannot gain privileges, and it can load a seccomp BPF filter that the caller passes through a file descriptor.
The table below lists the namespaces Bubblewrap can unshare and what each one hides from the sandboxed process.
| Namespace | Option | What the sandbox loses |
|---|---|---|
| User | --unshare-user | Real host user IDs and capabilities |
| Mount | Always created | The host mount table and unlisted paths |
| PID | --unshare-pid | Visibility of host processes |
| Network | --unshare-net | All host interfaces except a private loopback |
| IPC | --unshare-ipc | Host System V IPC and POSIX message queues |
| UTS | --unshare-uts | The host hostname |
| Cgroup | --unshare-cgroup | The host cgroup hierarchy view |
The convenience option --unshare-all requests every namespace at once, and --share-net can then restore network access when the application genuinely needs it. Inside a PID namespace, Bubblewrap normally runs a tiny init process as PID 1 to reap zombie children, unless --as-pid-1 hands that role to the target program.
Key options and their security meaning
The most important Bubblewrap options control which paths are visible and whether they are writable, because the filesystem view is where most sandbox escapes and data leaks begin. Each option is processed in the order given, so later mounts can shadow earlier ones.
| Option | Effect | Security consideration |
|---|---|---|
--ro-bind SRC DEST | Read-only bind mount | Preferred default for system directories |
--bind SRC DEST | Writable bind mount | Grant only to a dedicated work directory |
--dev-bind SRC DEST | Bind that keeps device nodes usable | Exposing /dev wholesale defeats isolation |
--dev /dev | Minimal private device tree | Provides null, zero, random, tty and shm only |
--proc /proc | Fresh procfs for the PID namespace | Hides host processes when combined with PID unsharing |
--tmpfs DEST | Empty in-memory directory | Masks a sensitive directory such as a home folder |
--die-with-parent | Kills the sandbox when the parent exits | Prevents orphaned sandboxed processes |
--new-session | Calls setsid() before exec | Blocks terminal input injection through TIOCSTI |
--cap-drop ALL | Drops capabilities inside the sandbox | Relevant when running with elevated privileges |
--clearenv | Starts with an empty environment | Stops secrets in variables from leaking inward |
The --new-session option deserves special attention. Without it, a sandboxed process that shares the controlling terminal can push characters into the parent shell through the TIOCSTI ioctl, a weakness tracked as CVE-2017-5226. Newer kernels can disable TIOCSTI globally, but adding --new-session or an equivalent seccomp rule remains standard hardening practice.
Bubblewrap compared with related Linux isolation tools
Bubblewrap differs from neighboring tools mainly in who defines the policy and what privileges are required. Several Linux security mechanisms overlap with it, and many are designed to be combined with it rather than replace it.
| Tool | Isolation basis | Policy source | Typical role |
|---|---|---|---|
| Bubblewrap | Namespaces, bind mounts, optional seccomp | Caller command line | Embeddable sandbox primitive |
| chroot | Changed root directory only | Administrator | Legacy confinement, not a security boundary |
| Firejail | Namespaces, seccomp, profiles | Shipped per-application profiles | Desktop application sandboxing |
| systemd-nspawn | Full namespace container | Container configuration | Running whole OS trees |
| AppArmor and SELinux | Mandatory access control in the kernel | System-wide policy | Host-level confinement |
| Landlock | Unprivileged LSM access rules | Process itself | Self-restriction of file access |
A key distinction concerns attack surface. Firejail is a large setuid-root program with rich profiles, which has historically produced privilege escalation bugs; Bubblewrap keeps its code base small and, in unprivileged mode, runs with no more rights than the calling user. Unlike AppArmor or SELinux, Bubblewrap cannot enforce rules on processes it did not start, so it complements mandatory access control rather than substituting for it.
Privileged and unprivileged operation
Bubblewrap runs in unprivileged mode whenever the kernel allows ordinary users to create user namespaces, which is the default on most current distributions. On older or hardened systems that disable this feature, the binary can be installed setuid root, in which case it drops privileges carefully and refuses options that would be dangerous with elevated rights.
Distribution policy now shapes this choice. Ubuntu 24.04, for example, restricts unprivileged user namespaces through AppArmor and ships a dedicated profile that permits bwrap to create them. Administrators who tighten kernel.unprivileged_userns_clone or similar settings must therefore verify that Flatpak and other Bubblewrap consumers still start.
| Situation | Recommended mode | Reason |
|---|---|---|
| Modern kernel with user namespaces enabled | Unprivileged | Smallest privilege footprint |
| Hardened kernel without user namespaces | Setuid installation | Only way to create namespaces |
| Ubuntu with namespace restriction | Unprivileged with AppArmor profile | Profile grants the needed permission |
| Nested inside another container | Unprivileged if host allows it | Setuid is often blocked by the outer runtime |
Limitations and common mistakes
The most common Bubblewrap mistake is assuming that any bwrap invocation is a strong sandbox. Security depends on the exact arguments, and several frequent shortcuts quietly remove most of the protection.
- Binding the whole home directory read-write exposes SSH keys, browser profiles and shell startup files that can be modified to persist outside the sandbox.
- Exposing the D-Bus or X11 socket lets the sandboxed program talk to host services; Flatpak filters D-Bus through a proxy for this reason.
- Omitting a seccomp filter leaves the full system call surface of the kernel reachable, including rarely used interfaces with known bugs.
- Forgetting `–unshare-net` keeps full network access, which matters when the goal is to stop data exfiltration.
- Relying on bwrap alone against kernel exploits ignores that namespaces share one kernel; a kernel vulnerability can break any namespace sandbox.
Bubblewrap also leaves resource limits to other mechanisms. It does not cap memory or CPU, so long-running sandboxes are usually placed in a systemd scope or cgroup to prevent a misbehaving program from exhausting the host.
The short version
Bubblewrap is a way to let a program run in a sealed room built just for it. Before the program starts, Bubblewrap decides which folders it can see, whether it can change them, whether it can reach the network and whether it can see other running programs. Everything else in the computer is simply absent from its view.
The tool itself does not decide what is safe. It is more like a set of building blocks, and the application that uses it chooses how tight the room should be. A careful setup gives strong protection; a careless one leaves the doors open.
Where it makes a difference
A software team reviews pull requests from outside contributors and wants to run each project’s test suite without risking developer laptops. The team wraps the test command in Bubblewrap: the system directories /usr and /etc are bound read-only, a fresh temporary copy of the repository is the only writable directory, the home folder is replaced by an empty tmpfs, and --unshare-all, --new-session and --die-with-parent are added.
One contribution contains a build script that tries to read ~/.ssh/id_ed25519 and send it to a remote server. Inside the sandbox, the key file does not exist and there is no network interface except loopback, so the script fails with ordinary file and connection errors. The test run completes in roughly the same time as before, and the team contains the malicious script without any root access or container infrastructure on the laptops.