MINIJAIL0(1)
okay so bestie, we're in minijail0(1) from the User Commands corner of the manual, and the whole vibe is: sandbox a process. No cap, that's the mission. π
πΈ NAME πΈ
minijail0 β sandbox a process
β¨ SYNOPSIS β¨
minijail0 [OPTION]... <PROGRAM> [args]...
π DESCRIPTION π
Runs PROGRAM inside a sandbox. That's the main-character energy right there. π«Ά
-a <table>β Run using the alternate syscall table namedtable. Only available on kernels and architectures that support thePR_ALT_SYSCALLoption ofprctl(2).-b <src>[,[dest][,<writeable>]], --bind-mount=<src>[,[dest][,<writeable>]]β Bind-mountsrcinto the chroot directory atdest, optionally writeable. Thesrcpath must be an absolute path. Ifdestis not specified, it will default tosrc. If the destination does not exist, it will be created as a file or directory based on thesrctype, including missing parent directories. To create a writable bind-mount setwriteableto1. If not specified it will default to0(read-only).-B <mask>β Skip setting securebits inmaskwhen restricting capabilities (-c).maskis a hex constant that represents the mask of securebits that will be preserved. Seecapabilities(7)for the complete list. By default,SECURE_NOROOT,SECURE_NO_SETUID_FIXUP, andSECURE_KEEP_CAPS(together with their respective locks) are set.SECBIT_NO_CAP_AMBIENT_RAISE(and its respective lock) is never set because the permitted and inheritable capability sets have already been set through-c.-c <caps>β Restrict capabilities tocaps, which is either a hex constant or a string that will be passed tocap_from_text(3)(only the effective capability mask will be considered). The value will be used as the permitted, effective, and inheritable sets. When used in conjunction with-uand-g, this allows a program to have access to only certain parts of root's default privileges while running as another user and group ID altogether. Note that these capabilities are not inherited by subprocesses of the process given capabilities unless those subprocesses have POSIX file capabilities or the--ambientflag is also passed. Seecapabilities(7).-C <dir>β Change root (usingchroot(2)) todir.-d,--mount-devβ Create a new/devmount with a minimal set of nodes. Implies-v. Additional nodes can be bound with the-bor-koptions.- The initial set of nodes are:
full null tty urandom zero. - Symlinks are also created for:
fd ptmx stderr stdin stdout. - Directories are also created for:
shm.
- The initial set of nodes are:
-e[file]β Enter a new network namespace, or iffileis specified, enter an existing network namespace specified byfile, which is typically of the form/proc/<pid>/ns/net.-f <file>β Write the pid of the jailed process tofile.-g <group|gid>β Change groups to the specified group name, or numeric group IDgid.-Gβ Inherit all the supplementary groups of the user specified with-u. It is an error to use this option without having specified a user name to-u.--add-suppl-group <group|gid>β Add the specified group name, or numeric group IDgid, to the process' supplementary groups list. Can be specified multiple times to add several groups. Incompatible with-yand-G.-hβ Print a help message.-Hβ Print a help message detailing supported system call names forseccomp_filter. (Other direct numbers may be specified ifminijail0is not in sync with the host kernel or something like 32/64-bit compatibility issues exist.)-iβ Exit immediately afterfork(2). The jailed process will keep running in the background. Normally minijail will fork+exec the specified program so that it can set up the right security settings in the new child process. The initial minijail process will stay resident and wait for the program to exit so the script that ran minijail will correctly block (e.g. standalone scripts). Specifying-imakes that initial process exit immediately and free up the resources. This option is recommended for daemons and init services when you want to background the long running program.-Iβ Run program as init (pid 1) inside a new pid namespace (implies-p). Most programs don't expect to run as an init which is why minijail will do it for you by default. Basically, the program needs to reap any processes it forks to avoid leaving zombies behind. Signal handling needs care since the kernel will mask all signals that don't have handlers registered (all default handlers are ignored and cannot be changed). This means a minijail process (acting as init) will remain resident by default. While using-Iis recommended when possible, strict review is required to make sure the program continues to work as expected.-iand-Imay be safely used together. The-ioption controls the first minijail process outside of the pid namespace while the-Ioption controls the minijail process inside of the pid namespace.-k <src>,<dest>,<type>[,<flags>[,<data>]], --mount=<src>,<dest>,<type>[,<flags>[,<data>]]β Mountsrc, atypefilesystem, atdest. If a chroot or pivot root is active,destwill automatically be placed below that path. Theflagsfield is optional and may be a mix ofMS_XXXor hex constants separated by|characters. Seemount(2)for details.MS_NODEV|MS_NOSUID|MS_NOEXECis the default value (a writable mount with nodev/nosuid/noexec bits set), and it is strongly recommended that all mounts have these three bits set whenever possible. If you need to disable all three, then specify something likeMS_SILENT. Thedatafield is optional and is a comma delimited string (seemount(2)for details). It is passed directly to the kernel, so all fields here are filesystem specific. For tmpfs, if no data is specified, we will default tomode=0755,size=10M. If you want other settings, you will need to specify them explicitly yourself. If the mount is not a pseudo filesystem (e.g.procorsysfs),srcpath must be an absolute path (e.g./dev/sda1and notsda1). If the destination does not exist, it will be created as a directory (including missing parent directories).-K[mode]β Don't mark all existing mounts asMS_SLAVE. This option is dangerous as it negates most of the functionality of-v. You very likely don't need this. You may specify a mount propagation mode in which case, that will be used instead of the defaultMS_SLAVE. See themount(2)man page and the kernel docsDocumentation/filesystems/sharedsubtree.txtfor more technical details, but a brief guide:slaveβ Changes in the parent mount namespace will propagate in, but changes in this mount namespace will not propagate back out. This is usually what people want to use, and is the default behavior if you don't specify-K.privateβ No changes in either mount namespace will propagate. This provides the most isolation.sharedβ Changes in the parent and this mount namespace will freely propagate back and forth. This is not recommended.unbindableβ Mark all mounts as unbindable.
-lβ Run inside a new IPC namespace. This option makes the program's System V IPC namespace independent.-Lβ Report blocked syscalls when using a seccomp filter. On kernels with support forSECCOMP_RET_LOG, every blocked syscall will be reported through the audit subsystem (seeseccomp(2)for more details onSECCOMP_RET_LOGavailability.) On all other kernels, the first failing syscall will be logged to syslog. This latter case will also force certain syscalls to be allowed in order to write to syslog. Note: this option is disabled and ignored for release builds.-m[<uid> <loweruid> <count>[,<uid> <loweruid> <count>]]β Set the uid mapping of a user namespace (implies-pU). Same arguments asnewuidmap(1). Multiple mappings should be separated by,. With no mapping, map the current uid to root inside the user namespace.-M[<uid> <loweruid> <count>[,<uid> <loweruid> <count>]]β Set the gid mapping of a user namespace (implies-pU). Same arguments asnewgidmap(1). Multiple mappings should be separated by,. With no mapping, map the current gid to root inside the user namespace.-nβ Set the process'sno_new_privsbit. Seeprctl(2)and the kernel source fileDocumentation/userspace-api/no_new_privs.txtfor more info.-Nβ Run inside a new cgroup namespace. This option runs the program with a cgroup view showing the program's cgroup as the root. This is only available on v4.6+ of the Linux kernel.-pβ Run inside a new PID namespace. This option will make it impossible for the program to see or affect processes that are not its descendants. This implies-vand-r, since otherwise the process can see outside its namespace by inspecting/proc. If the program exits, all of its children will be killed immediately by the kernel. If you need to daemonize or background things, use the-ioption. Seepid_namespaces(7)for more info.-P <dir>β Setdiras the root fs usingpivot_root. Implies-v, not compatible with-C.-rβ Remount/procreadonly. This implies-v. Remounting/procreadonly means that even if the process has write access to a system config knob in/proc(e.g., in/sys/kernel), it cannot change the value.-R <rlim_type>,<rlim_cur>,<rlim_max>β Set an rlimit value, seegetrlimit(2)for more details.rlim_typemay be specified using symbolic constants likeRLIMIT_AS.rlim_curandrlim_maxare specified either with a number (decimal or hex starting with0x), or with the stringunlimited(which will translate toRLIM_INFINITY).-sβ Enableseccomp(2)in mode 1, which restricts the child process to a very small set of system calls. You most likely do not want to use this with the seccomp filter mode (-S) as they are completely different (even though they have similar names).-S <arch-specific seccomp_filter policy file>β turns onseccomp(2)in mode13, bestie, which locks the child process down to only the system calls listed in that policy file π₯. Heads up: syscall names can be different depending on the runtime environment, so peek atminijail0(5)for the full tea β.-t[size]β mounts atmpfsfilesystem on/tmpβ¨./tmphas to already exist (like, inside the chroot, okay?). Default size is"64M", and you can override it with the optional argument. It gets standard/tmppermissions (1777) and is mountednodev/noexec/nosuid. This implies-vπ .-T <type>β tells minijail0 to assume the binaryβs ELF linkage type is type, which must be either'static'or'dynamic'π. Either one stopsminijail0from manually parsing the ELF header to figure the type out.'static'can be used to avoid preload hooking and forcesminijail0to set everything up before the program is executed.'dynamic'forcesminijail0to preloadlibminijailpreload.soto set up hooks, but bestie, it will fail on actually statically-linked binaries π.-u <user|uid>β changes users to the specified user name, or to the numeric user ID uid π«Ά.-Uβ enters a new user namespace. This implies-pπ.-v,--ns-mountβ runs inside a new VFS namespace π. This stops mounts performed by the program from affecting the rest of the system (but see-K, okay?).-V <file>β enters the VFS namespace specified by file π¦.-wβ creates and joins a new anonymous session keyring π. Seekeyrings(7)for more details.-yβ keeps the current userβs supplementary groups π.-Yβ synchronizes seccomp filters across the thread group π―.-zβ doesnβt forward any signals to the jailed process π. For example, when not using-i, sendingSIGINT(like Ctrl+C on the terminal) will kill theminijail0process, not the jailed process. Important vibe check π.--ambientβ raises ambient capabilities to match the mask specified by-cβ¨. Since ambient capabilities are preserved acrossexecve(2), this lets process trees have a restricted set of capabilities even if theyβre capability-dumb binaries. Seecapabilities(7)π§.--uts[=hostname]β creates a new UTS/hostname namespace, and optionally sets the hostname in the new namespace to hostname πΈ.--env-resetβ clears the current environment instead of letting the program inherit the active environment π§Ό. This is often used to start the program with a minimal sanitized environment.--env-add <NAME=value>β adds or replaces the specified environment variableNAMEin the programβs environment before starting it, and sets it to the specified value π . You can use this option several times to set any number of environment variables.--logging=<system>β uses system as the logging system. system must be one ofauto(the default),syslog, orstderrπ.autowill usestderrif connected to a tty (like when run directly by a user), otherwise it will usesyslog. Slay.--profile <profile>β chooses one of the available sandboxing profiles, which are a simple way to get a standardized environment π. See the SANDBOXING PROFILES section below for the full list of supported values for profile.--preload-library <file path>β lets you override the default path of/lib/libminijailpreload.soπ. This is only really useful for testing, ngl.--seccomp-bpf-binary <arch-specific BPF binary>β similar to-S, but instead of using a policy file,--secomp-bpf-binaryexpects an arch-and-kernel-version-specific pre-compiled BPF binary (such as the ones produced byparse_seccomp_policy) π₯. Note that the filter might be different based on the runtime environment; seeminijail0(5)for more details.--allow-speculative-executionβ allows speculative execution features that may cause data leaks across processes π¬. This passes theSECCOMP_FILTER_FLAG_SPEC_ALLOWflag to seccomp, which disables mitigations against certain speculative execution attacks β namely Branch Target Injection (spectre-v2) and Speculative Store Bypass (spectre-v4). These mitigations incur a runtime performance hit, so itβs useful to be able to disable them in order to quantify their performance impact.
β οΈ WARNING: It is dangerous to use this option on programs that process untrusted input, which is normally what Minijail is used for. Do not enable this option unless you know what youβre doing, bestie. Fr fr.
See the kernel documentation Documentation/userspace-api/spec_ctrl.rst and Documentation/admin-guide/hw-vuln/spectre.rst for more information π.
--fs-default-pathsβ adds a set of allowed paths to allow running common system executables π€οΈ.
Landlock support: This flag, and the following --fs* flags, impact what filesystem access is available and require kernel support for Landlock in order to be enforced π¦. Landlock is available on Linux kernels >= 5.13, or ChromeOS kernels >= 5.10, as long as it is configured to be available as outlined in the Landlock kernel docs at https://docs.kernel.org/userspace-api/landlock.html#kernel-support.
Flag combinations: As long as --fs-path* or --fs-default-paths are used, Minijail will utilize Landlock if it is available β¨. Additional --fs-path* flags used will expand the allowlisted paths and access rights.
--enable-profile-fs-restrictionsβ limits paths available when usingminimalistic-mountnsπ.--fs-path-rxβ adds an allowed read-execute path π.--fs-path-roβ adds an allowed read-only path πΈ.--fs-path-rwβ adds an allowed read-write path βοΈ.--fs-path-advanced-rwβ adds an allowed advanced read-write path π .--no-fs-restrictionsβ disables path-based filesystem restrictions π .--no-default-runtime-environmentβ disables the default seccomp policy and setting ofno_new_privsπ. The default runtime environment is used by Minijail if no other seccomp policy is set, unless this flag is set to opt out.--no-new-sessionsβ skips having Minijail callsetsid()π. This is useful when running a process that expects to have a controlling terminal set.--preserve-fdβ preserves an fd and makes it available in the child process π«Ά. The fd is preserved with the same integer value.--config <file path>β uses a Minijail configuration file to set options through commandline-option-equivalent key-value pairs π. Seeminijail0(5)for more details on the format of the configuration file.
πΈ SANDBOXING PROFILES πΈ
The following sandboxing profiles are supported, bestie:
minimalistic-mountnsβ sets up a minimalistic mount namespace β¨. Equivalent to-v -P /var/empty -b / -b /proc -b /dev/log -t -r --mount-dev.minimalistic-mountns-nodevβ sets up a minimalistic mount namespace with an empty/devpath π. Equivalent to-v -P /var/empty -b/ -b/proc -t -r.
π οΈ IMPLEMENTATION π οΈ
This program is broken up into two parts: minijail0 (the frontend) and a helper library called libminijailpreload π. Some jailings can only be achieved from the process to which they will actually apply:
- capability use (without using ambient capabilities): non-ambient capabilities are not inherited across
execve(2)unless the file being executed has POSIX file capabilities π . Ambient capabilities (the--ambientflag) fix capability inheritance acrossexecve(2)to avoid the need for file capabilities. - seccomp: a meaningful seccomp filter policy should disallow
execve(2), to prevent a compromised process from executing a different binary π₯. However, this would prevent the seccomp policy from being applied beforeexecve(2). Iconic problem, honestly.
To this end, libminijailpreload is forcibly loaded into all dynamically-linked target programs by default π«Ά; we pass the specific restrictions in an environment variable which the preloaded library looks for. The forcibly-loaded library then applies the restrictions to the newly-loaded program β¨.
This behavior can be disabled by the use of the -T static flag. There are other cases in which the use of this flag might be useful:
- When program is linked against a different version of
libc.sothanlibminijailpreload.soπ. - When
execve(2)has side-effects that interact badly with the jailing process. If the system uses SELinux,execve(2)can cause an automatic domain transition, which would then require that the target domain allows the operations to jail program π.
π AUTHOR π
The ChromiumOS Authors <chromiumos-dev@chromium.org>
π COPYRIGHT π
Copyright Β© 2011 The ChromiumOS Authors License BSD-like.
π SEE ALSO π
libminijail.h, minijail0(5), seccomp(2)
made with maximum main-character energy by ChromiumOS, March 2016, MINIJAIL0(1) π«Άβ¨
π¦ where this page comes from
- nixos 26.05: minijail 2025.07.02
- nixpkgs unstable: minijail 2026.05.18
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms