Bubblewrap

Also known as: bwrap

On this page 7

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.

NamespaceOptionWhat the sandbox loses
User--unshare-userReal host user IDs and capabilities
MountAlways createdThe host mount table and unlisted paths
PID--unshare-pidVisibility of host processes
Network--unshare-netAll host interfaces except a private loopback
IPC--unshare-ipcHost System V IPC and POSIX message queues
UTS--unshare-utsThe host hostname
Cgroup--unshare-cgroupThe host cgroup hierarchy view
Namespaces available to bwrap

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.

OptionEffectSecurity consideration
--ro-bind SRC DESTRead-only bind mountPreferred default for system directories
--bind SRC DESTWritable bind mountGrant only to a dedicated work directory
--dev-bind SRC DESTBind that keeps device nodes usableExposing /dev wholesale defeats isolation
--dev /devMinimal private device treeProvides null, zero, random, tty and shm only
--proc /procFresh procfs for the PID namespaceHides host processes when combined with PID unsharing
--tmpfs DESTEmpty in-memory directoryMasks a sensitive directory such as a home folder
--die-with-parentKills the sandbox when the parent exitsPrevents orphaned sandboxed processes
--new-sessionCalls setsid() before execBlocks terminal input injection through TIOCSTI
--cap-drop ALLDrops capabilities inside the sandboxRelevant when running with elevated privileges
--clearenvStarts with an empty environmentStops secrets in variables from leaking inward
Frequently used bwrap options

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

ToolIsolation basisPolicy sourceTypical role
BubblewrapNamespaces, bind mounts, optional seccompCaller command lineEmbeddable sandbox primitive
chrootChanged root directory onlyAdministratorLegacy confinement, not a security boundary
FirejailNamespaces, seccomp, profilesShipped per-application profilesDesktop application sandboxing
systemd-nspawnFull namespace containerContainer configurationRunning whole OS trees
AppArmor and SELinuxMandatory access control in the kernelSystem-wide policyHost-level confinement
LandlockUnprivileged LSM access rulesProcess itselfSelf-restriction of file access
How bwrap relates to other isolation mechanisms

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.

SituationRecommended modeReason
Modern kernel with user namespaces enabledUnprivilegedSmallest privilege footprint
Hardened kernel without user namespacesSetuid installationOnly way to create namespaces
Ubuntu with namespace restrictionUnprivileged with AppArmor profileProfile grants the needed permission
Nested inside another containerUnprivileged if host allows itSetuid is often blocked by the outer runtime
Choosing an operating mode

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.