BWRAP(1)
๐ BWRAP(1) ๐
Manual name: bwrap ยท section: User Commands ๐ซถ
โจ NAME โจ
bwrap โ container setup utility ๐ ๏ธ
๐ฆ SYNOPSIS ๐ฆ
bwrap [OPTION...] [COMMAND]
๐ DESCRIPTION ๐
okay so bwrap is an unprivileged low-level sandboxing tool. bestie, you're probably not gonna use it straight from the commandline every day, but you can โ it's totally possible. ๐
It works by making a brand-new, completely empty filesystem namespace where the root lives on a tmpfs that the host can't see, and that whole thing gets automatically cleaned up when the last process exits. โจ Then you use commandline options to build the root filesystem and the process environment for the command that's gonna run in that namespace. It's giving custom tiny universe energy. ๐
By default, bwrap creates a new mount namespace for the sandbox. Optionally it also sets up new user, ipc, pid, network and uts namespaces โ but heads up, the user namespace is required if bwrap is not run as root. The application in the sandbox can be made to run with a different UID and GID. ๐
If needed (e.g. when using a PID namespace), bwrap runs a minimal pid 1 process in the sandbox that is responsible for reaping zombies. It also detects when the initial application process (pid 2) dies and reports its exit status back to the original spawner. The pid 1 process exits to clean up the sandbox when there are no other processes in the sandbox left. no cap, that little pid 1 is doing main character cleanup duty. ๐งน
๐ OPTIONS ๐
When options are used multiple times, the last option wins, unless otherwise specified.
An empty string is not a valid path, so options that take a path reject it with an error. ๐จ
๐ General options ๐
--helpโ print help and exit. cute, quick, done. โจ--versionโ print version. ๐ท๏ธ--args FDโ parse nul-separated arguments from the given file descriptor. This option can be used multiple times to parse options from multiple sources. ๐ซถ--argv0 VALUEโ setargv[0]to the value VALUE before running the program. ๐--level-prefixโ prefix each line of diagnostic output with a numeric severity level enclosed in angle brackets. The severity levels used are based on the constants used bysyslog(3): for example,<4>indicates a warning, becauseLOG_WARNINGhas numeric value4. Numbers smaller than4indicate fatal errors, and numbers larger than4indicate informational messages. These prefixes can be parsed by tools compatible withlogger --prio-prefix(seelogger(1)) orsystemd-cat --level-prefix=1(seesystemd-cat(1)). ๐ชต
๐ง Options related to kernel namespaces ๐ง
--unshare-userโ create a new user namespace. ๐ค--unshare-user-tryโ create a new user namespace if possible, else skip it. ๐--unshare-ipcโ create a new ipc namespace. ๐ฌ--unshare-pidโ create a new pid namespace. ๐งธ--unshare-netโ create a new network namespace. ๐--unshare-utsโ create a new uts namespace. ๐ท๏ธ--unshare-cgroupโ create a new cgroup namespace. ๐งบ--unshare-cgroup-tryโ create a new cgroup namespace if possible, else skip it. ๐ซง--unshare-allโ unshare all possible namespaces. Currently equivalent with:--unshare-user-try --unshare-ipc --unshare-pid --unshare-net --unshare-uts --unshare-cgroup-try. โจ--share-netโ retain the network namespace, overriding an earlier--unshare-allor--unshare-net. ๐--userns FDโ use an existing user namespace instead of creating a new one. The namespace must fulfil the permission requirements forsetns(), which generally means that it must be a descendant of the currently active user namespace, owned by the same user. ๐--userns2 FDโ after setting up the new namespace, switch into the specified namespace. For this to work the specified namespace must be a descendant of the user namespace used for the setup, so this is only useful in combination with--userns.
This is useful because sometimes bubblewrap itself creates nested user namespaces (to work around some kernel issues) and --userns2 can be used to enter these. ๐
--disable-usernsโ prevent the process in the sandbox from creating further user namespaces, so that it cannot rearrange the filesystem namespace or do other more complex namespace modification. This is currently implemented by setting theuser.max_user_namespacessysctl to1, and then entering a nested user namespace which is unable to raise that limit in the outer namespace. This option requires--unshare-user. ๐--assert-userns-disabledโ confirm that the process in the sandbox has been prevented from creating further user namespaces, but without taking any particular action to prevent that. For example, this can be combined with--usernsto check that the given user namespace has already been set up to prevent the creation of further user namespaces. โ--pidns FDโ use an existing pid namespace instead of creating one. This is often used with--userns, because the pid namespace must be owned by the same user namespace thatbwrapuses.
Note that this can be combined with --unshare-pid, and in that case it means that the sandbox will be in its own pid namespace, which is a child of the passed in one. ๐งธ
--uid UIDโ use a custom user id in the sandbox (requires--unshare-user). ๐ชช--gid GIDโ use a custom group id in the sandbox (requires--unshare-user). ๐ซถ--hostname HOSTNAMEโ use a custom hostname in the sandbox (requires--unshare-uts). ๐ท๏ธ
๐ธ Options about environment setup ๐ธ
--chdir DIRโ change directory to DIR. ๐--setenv VAR VALUEโ set an environment variable. ๐ฑ--unsetenv VARโ unset an environment variable. ๐--clearenvโ unset all environment variables, except forPWDand any that are subsequently set by--setenv. ๐งผ
๐ฆ Options for monitoring the sandbox from the outside ๐ฆ
--lock-file DESTโ take a lock on DEST while the sandbox is running. This option can be used multiple times to take locks on multiple files. ๐--sync-fd FDโ keep this file descriptor open while the sandbox is running. ๐ก
๐ Filesystem related options ๐
These are all operations that modify the filesystem directly, or mounts stuff in the filesystem. These are applied in the order they are given as arguments. ๐ง
Any missing parent directories that are required to create a specified destination are automatically created as needed. Their permissions are normally set to 0755 (rwxr-xr-x). However, if a --perms option is in effect, and it sets the permissions for group or other to zero, then newly-created parent directories will also have their corresponding permission set to zero. --size modifies the size of the created mount when preceding a --tmpfs action; --perms and --size can be combined. โจ
--perms OCTALโ this option does nothing on its own, and must be followed by one of the options that it affects. It sets the permissions for the next operation to OCTAL. Subsequent operations are not affected: for example,--perms 0700 --tmpfs /a --tmpfs /bwill mount/awith permissions0700, then return to the default permissions for/b. Note that--permsand--sizecan be combined:--perms 0700 --size 10485760 --tmpfs /swill apply permissions as well as a maximum size to the created tmpfs. ๐--size BYTESโ this option does nothing on its own, and must be followed by--tmpfs. It sets the size in bytes for the next tmpfs. For example,--size 10485760 --tmpfs /tmpwill create a tmpfs at/tmpof size10MiB. Subsequent operations are not affected: for example,--size 10485760 --tmpfs /a --tmpfs /bwill mount/awith size10MiB, then return to the default size for/b. Note that--permsand--sizecan be combined:--size 10485760 --perms 0700 --tmpfs /swill apply permissions as well as a maximum size to the created tmpfs. ๐--bind SRC DESTโ bind mount the host path SRC on DEST. ๐--bind-try SRC DESTโ equal to--bindbut ignores non-existent SRC. ๐--dev-bind SRC DESTโ bind mount the host path SRC on DEST, allowing device access. ๐๏ธ--dev-bind-try SRC DESTโ equal to--dev-bindbut ignores non-existent SRC. ๐ซง--ro-bind SRC DESTโ bind mount the host path SRC readonly on DEST. ๐ง--ro-bind-try SRC DESTโ equal to--ro-bindbut ignores non-existent SRC. ๐--remount-ro DESTโ remount the path DEST as readonly. It works only on the specified mount point, without changing any other mount point under the specified path. ๐--overlay-src SRCโ this option does nothing on its own, and must be followed by one of the other overlay options. It specifies a host path from which files should be read if they aren't present in a higher layer.
This option can be used multiple times to provide multiple sources. The sources are overlaid in the order given, with the first source on the command line at the bottom of the stack: if a given path to be read exists in more than one source, the file is read from the last such source specified. ๐ฅ
(For readers familiar with overlayfs, note that this is the reverse of the order used by the kernel's lowerdir mount option.) ๐
--overlay RWSRC WORKDIR DESTโ writable overlay vibes: writes go to RWSRC, reads prefer RWSRC, then the--overlay-srcpaths. WORKDIR must be an empty directory on the same filesystem as RWSRC, and is used internally by the kernel. ๐ง--tmp-overlay DESTโ overlay where writes go to the tmpfs that hosts the sandbox root, in a location not accessible from either the host or the child process. Writes will therefore not be persisted across multiple runs. ๐ซง--ro-overlay DESTโ overlay mounted read-only. This option requires at least two--overlay-srcto precede it. ๐ง
All three overlay options use overlayfs to mount the host paths specified by RWSRC and all immediately preceding --overlay-src on DEST. DEST will contain the union of all the files in all the layers. ๐
Using --ro-overlay or providing more than one --overlay-src requires a Linux kernel version of 4.0 or later. ๐ง
overlayfs limitation alert ๐จ due to limitations of overlayfs, no host directory given via--overlay-srcor--overlaymay be an ancestor of another, after resolving symlinks. Depending on version, the Linux kernel may or may not enforce this, but if not then overlayfs's behavior is undefined.
For more information see the Overlay Filesystem documentation in the Linux kernel at https://www.kernel.org/doc/Documentation/filesystems/overlayfs.txt. ๐
--proc DESTโ mount procfs on DEST. ๐๏ธ--dev DESTโ mount new devtmpfs on DEST. ๐๏ธ--tmpfs DESTโ mounts a brand-newtmpfsatDEST๐ if the option right before it was--perms, that sets the mode of the tmpfs (cute!). Otherwise the tmpfs gets mode0755. And if the previous option was--size, that sets the size in bytes of the tmpfs. Otherwise it just rocks the default size, no cap โจ--mqueue DESTโ mounts a freshmqueueatDEST๐--dir DESTโ makes a directory atDEST๐ฆ real talk though: if the directory already exists, its permissions stay unmodified and--permsgets straight-up ignored (use--chmodif you actually need to change perms on a directory that's already there, iykyk). If it's newly created and the previous option was--perms, that sets the mode. Otherwise newly-created directories get mode0755. periodt ๐--file FD DESTโ copies from the file descriptorFDtoDEST๐ธ if the previous option was--perms, it sets the mode of the new file. Otherwise the file gets mode0666(and yes, note that this is not the same as--bind-data, don't @ me ๐ญ)--bind-data FD DESTโ copies from the file descriptorFDto a file which is bind-mounted onDEST๐ if the previous option was--perms, it sets the mode of the new file. Otherwise the file gets mode0600(note that this is not the same as--file, they're literally different beasts ๐ซถ)--ro-bind-data FD DESTโ copies from the file descriptorFDto a file which is bind-mounted read-only onDEST๐ง if the previous option was--perms, it sets the mode of the new file. Otherwise the file gets mode0600(again: note that this is not the same as--fileโญ)--symlink SRC DESTโ creates a symlink atDESTwith targetSRC๐
Since version 0.9.0, it is not considered an error if DEST already exists as a symbolic link and its target is exactly SRC ๐
Before version 0.9.0, if DEST already existed, this would be treated as an error โ even if its target was identical to SRC ๐ historic L tbh
--chmod OCTAL PATHโ sets the permissions ofPATH(which must already exist, no exceptions bestie) toOCTAL๐
๐ Lockdown options ๐
--seccomp FDโ loads and uses seccomp rules fromFD๐ก๏ธ the rules need to be in the form of a compiled cBPF program, as generated byseccomp_export_bpf. If this option is given more than once, only the last one is used (rude but true ๐). Use--add-seccomp-fdif multiple seccomp programs are needed.--add-seccomp-fd FDโ loads and uses seccomp rules fromFDโจ rules need to be a compiled cBPF program, as generated byseccomp_export_bpf. This option can be repeated, in which case all the seccomp programs get loaded in the order given โ though heads up, the kernel evaluates them in reverse order, so the last program on the bwrap command-line is evaluated first ๐. All of them, except possibly the last, must allow use of thePR_SET_SECCOMPprctl. Also: this option cannot be combined with--seccomp๐ซ--exec-label LABELโ exec label from the sandbox ๐ on an SELinux system you can specify the SELinux context for the sandbox process(s). iconic.--file-label LABELโ file label for temporary sandbox content ๐ on an SELinux system you can specify the SELinux context for the sandbox content.--block-fd FDโ blocks the sandbox on reading fromFDuntil some data is available โณ (the sandbox is literally waiting on you, main character energy)--userns-block-fd FDโ does not initialize the user namespace but waits onFDuntil it is ready ๐ฆ this lets external processes (likenewuidmap/newgidmap) set up the user namespace before it gets used by the sandbox process. teamwork fr fr.--info-fd FDโ writes information in JSON format about the sandbox toFD๐ธ--json-status-fd FDโ multiple JSON documents are written toFD, one per line ("JSON lines" format[1] โจ). Each line is a single JSON object. After bwrap has started the child process inside the sandbox, it writes an object with achild-pidmember to the--json-status-fd(this duplicates the older--info-fd). The corresponding value is the process ID of the child process in the pid namespace from whichbwrapwas run. If available, the namespace IDs are also included in the object with thechild-pid; again, this duplicates the older--info-fd. When the child process inside the sandbox exits, bwrap writes an object with anexit-codemember, and then closes the--json-status-fd. The value corresponding toexit-codeis the exit status of the child, in the usual shell encoding (nif it exited normally with statusn, or128+nif it was killed by signaln) ๐งฎ Other members may be added to those objects in future versions of bwrap, and other JSON objects may be added before or after the current objects โ so readers must ignore members and objects that they do not understand. no cap, forward-compatible or bust ๐--new-sessionโ creates a new terminal session for the sandbox (callssetsid()) ๐ this disconnects the sandbox from the controlling terminal, which means the sandbox can't for instance inject input into the terminal ๐
Note: in a general sandbox, if you don't use--new-session, it is recommended to use seccomp to disallow theTIOCSTIioctl ๐ญ otherwise the application can feed keyboard input to the terminal which can e.g. lead to out-of-sandbox command execution (seeCVE-2017-5226). that one is genuinely scary, don't skip it ๐
--die-with-parentโ ensures the child process (COMMAND) dies when bwrap's parent dies ๐ชฆ it kills (SIGKILL) all bwrap sandbox processes in sequence from parent to child, including theCOMMANDprocess, when bwrap or bwrap's parent dies. Seeprctl,PR_SET_PDEATHSIG. loyal to the end fr ๐ซถ--as-pid-1โ does not create a process withPID=1in the sandbox to reap child processes ๐ (so yes, you have to deal with the zombie reaping, good luck bestie)--cap-add CAPโ adds the specified capabilityCAP, e.g.CAP_DAC_READ_SEARCH, when running as privileged user โจ it accepts the special valueALLto add all the permitted caps ๐--cap-drop CAPโ drops the specified capability when running as privileged user ๐ฅ it accepts the special valueALLto drop all the caps. By default no caps are left in the sandboxed process. The--cap-addand--cap-dropoptions are processed in the order they are specified on the command line โ so please be careful about the order they are specified in โ ๏ธ (order matters, that's the whole vibe)--not-a-security-boundaryโ declares that this invocation of bwrap is not intended to create a security boundary between the sandbox and the host system ๐ง when this option is given, certain non-fatal sandbox setup failures (such as a subdirectory remount failing because an automounter did not respond in time) will produce a warning and be skipped, rather than causing bwrap to exit with an error. In future releases of bubblewrap the effect of this option might be extended to make other sandbox setup operations non-fatal ๐
This option is intended for callers such as xdg-dbus-proxy or Steam that use bwrap to adjust the filesystem layout for a process, but do not rely on it to create a security boundary ๐ฎ
Other operations that are fundamental to establishing the sandbox (creating namespaces, pivot_root, dropping capabilities) will still cause a hard failure regardless of this option ๐ so no, this isn't a magic "ignore everything" button, bestie.
๐ธ ENVIRONMENT ๐ธ
HOMEโ used as the cwd in the sandbox if--chdirhas not been explicitly specified and the current cwd is not present inside the sandbox ๐ the--setenvoption can be used to override the value that is used here ๐
โจ EXIT STATUS โจ
The bwrap command returns the exit status of the initial application process (pid 2 in the sandbox) ๐ซถ so like, whatever your app said on the way out is what bwrap echoes back. periodt.
๐ NOTES ๐
- "JSON lines" format
https://jsonlines.org/๐
and that's a wrap on the bwrap(1) page, bestie ๐ source is the Containers section, page BWRAP(1) โ go forth and sandbox responsibly, mwah ๐
โจ๐ฆ
๐ฆ where this page comes from
- arch rolling: bubblewrap 0.13.1-1 ยท LGPL-2.1-or-later
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms