The Linux envelope

On Linux every confined command runs inside a bwrap envelope: a private view of the filesystem and a private set of namespaces, built for that one command. This page says what the envelope mounts, what it shows the child, and how it copes with hosts that refuse parts of it. How a command enters it is confined-launch; how its denies hold is holding-a-deny.

The envelope is the child’s whole world

bwrap_command wraps each child in bwrap, and the envelope covers more than the filesystem (the-envelope-is-a-process-namespace).

  • Namespaces. Every projection gets its own ipc, uts and cgroup namespaces. Wherever the host can build one, it also gets a pid namespace with a fresh /proc. A confined child then sees and can signal nothing of the host, /proc/self is its own, and ps under any grant shows only the envelope.
  • Unix sockets. net: `offline adds --unshare-net; otherwise the child shares the host’s network namespace. Landlock’s ABI 6 abstract-socket scope refuses connections to abstract sockets bound outside the envelope. On ABI 9 (Linux 7.1), RESOLVE_UNIX admits outside pathname sockets only where a stated fs write prefix covers their path; unrestricted fs admits none. A socket-file write admits that file alone. A read-only bind does not gate connect; an fs deny hides the socket behind bwrap’s mask. Below ABI 9, every pathname socket a bind shows stays reachable, including offline. unix-sockets-follow-writes records the policy and its deputy concession.
  • Working directory. The context’s absolute CwdPath goes in as --chdir. A cwd the grant does not cover gets an empty 0555 tmpfs stand-in, laid before the binds, which may hide it; bwrap’s --chdir then judges the name. / and the scratch /tmp are the envelope’s own writable memory and need none. So a grant narrower than the cwd still runs commands, as under Seatbelt, and a relative write in a stand-in is refused. A cwd at or beneath a deny is refused before bwrap runs, since no mask can be entered.
  • The payload’s group. bwrap never execs the payload in place: a monitor clones a process that calls setsid (--new-session) and then, as the pid namespace’s init, forks the payload, or without one becomes it. So a Kept launch reads that process’s pid back over --info-fd (InfoFd, a socketpair), and its group is the one every signal ladder targets. No same-uid process can reopen a socketpair through /proc to forge a child-pid. Nothing addresses the monitor.
  • The group is named only once it exists. bwrap writes child-pid before that setsid, when a signal to the group would be lost. The payload holds a second copy of the writer, which bwrap does not name, until its handoff sweep, so the read ends only once the group exists or the envelope has died, and EnvelopedLaunch::spawn returns no sooner. An empty record means bwrap died before reporting; an unreadable or malformed one makes the spawn kill and reap the envelope, then return an error.
  • A deny line names a host pid. The seccomp record carries the denied process’s host pid, which no process inside the namespace can name. So a confined start claims the chain beneath the payload’s group leader (init, supervisor, program), read from the host’s /proc/<pid>/task/*/children once the trampoline has said started (payload_pids). A program dead within microseconds of its start, and every descendant born later, go unclaimed (an-external-end-to-end).
  • A failed birth kills the group it named. Launch::born asks for the payload’s group before it hears the report. A refusal, a vanished envelope or a stop after that kills the payload’s group, then the monitor’s, and only then reaps the monitor. Without a pid namespace the monitor’s death reaches the supervisor and its program alone; the group kill reaches what the program forked (a-group-id-is-held-until-its-last-kill).
  • The envelope is a launch type, not a placement flag. EnvelopedLaunch owns its inner launch and the naming of its payload’s group; the inner launch holds the report and the diagnostics file under bwrap’s name. Its spawn calls Launch::born with Step::NewLeader, whatever placement was requested, and lands on Group::Enveloped, the payload’s separate-session group. Confinement::denial_pids claims denial pids from that group. No loan targets an envelope. A requested Tenant keeps readable terminal stdin and consumes its pre-spawn capture through PreparedTerminalLoan::guard: an opaque TerminalHold restores modes on settlement or drop without key attribution. This applies even in a non-interactive script, but requires access to reach the session lease, not merely a held lease. A refused start retains the capture until child teardown, restores state and releases the jail, then the shell joins all started output drains before reporting failure. A pipeline collector addresses each confined stage’s envelope beside its own group (pipeline execution).

bwrap mounts what ral opened, never a name

Binds::open plans every bind a launch shows, opens each object once without following a symlink, and lends a copy per bind (the-envelope-mounts-by-handle). bwrap_argv emits --ro-bind-fd or --bind-fd from the same vector. The binds are: the read-only defaults, the read region (shown: every read scope of the fs projection, run places and live support among them, written prefixes included), each directory that holds a deny in place, bound writable onto its own name after the read region and before the masks (holding-a-deny), the pins of bwrap and the trampoline, bound read-only at their own names before the masks, and, over everything, the cgroup tree. The launched image is not a bind of its own: the running-reads law puts it in the read region, and the table admits it as it admits any file. Every allowance is bound as the resolved position the guard judged, opened without following a link (open_nofollow) and never resolved again; the spelling is only the destination at which the opened object is bound.

  • A path is its canonical object plus the spellings that reach it (render_objects). /bin shows /usr/bin’s handle, except inside another bind, where the host’s own link already stands.
  • Redundant binds are dropped. A read-only bind inside another bind adds nothing. A writable bind is dropped only inside a writable one.
  • A redirected allowance refuses the launch. Every bind object opens with openat2(RESOLVE_NO_SYMLINKS), so a symlink put anywhere on a frozen allowance’s path refuses the launch, naming it, rather than following it, in the words Windows gives a redirect (remedy::grant_the_new_target).
  • There is no write freeze. No bind is laid read-only over an admitted directory a write covers; the protection it gave is a declared limit (authority-is-belnap-evidence).
  • Missing objects are dropped, changed ones refused. An absent object drops its binds at the open, and so does a system default this user may not reach: the projection marks which reads the Baseline supplied (FsLists::tolerated, folded where the baseline is), so no launch is handed the baseline itself. A name that now reaches another object, or an open through a symlink, refuses the launch and says which.
  • Every deny is masked at every name a bind shows it. A deny that would hide /proc, which bwrap execs the trampoline through, is refused. An Over bind replaces names beneath its destination with those it shows: a cgroup deny outside ral’s subtree needs no mask, and one inside follows the re-root.
  • Each deny is read once, at planning (a-deny-is-read-once). Shown::of reads them; bwrap_argv renders the planned masks and landlock::build takes the same Shown.
  • An unusable bwrap refuses in its own words. A bwrap that builds no envelope refuses every confined launch. A failed --ro-bind-fd probe keeps bwrap’s own error; only an unknown-option error adds the version question. A bwrap that mounts a descriptor through a symlinked destination, lacking the check of 0.10.0, refuses every confined launch too.

Pinned by authority::sandbox::linux::tests::render::a_bind_is_opened_for_each_name_no_other_bind_shows, ::a_prefix_whose_component_became_a_symlink_since_render_is_refused, ::every_bind_is_a_handle_by_slot_in_layer_order, ::a_write_through_a_link_is_masked_at_both_its_names, ::bwrap_and_landlock_take_each_denys_mask_from_one_read, ::a_denys_spine_is_bound_onto_itself_between_the_binds_and_the_masks, ::a_pinned_directory_turned_link_refuses_the_launch and, spawning, ::a_prefix_swapped_for_a_symlink_after_the_open_shows_what_was_opened.

The exec layer is lowered against the binds

Landlock rules attach to host objects opened before bwrap starts, and a walk from a file inside the envelope meets only the inodes above it in the envelope. So the bind plan, with its objects, is computed before the ruleset and passed to landlock::build: its roots, onto which a directory admission is lowered, and its planned deny masks, which no admission may reach from above.

Inside a restricted envelope a bind’s root has the envelope’s own directories above it, so a rule on a host directory above a bind root is off every walk inside that bind (the payload’s REFER admission already worked around this for the envelope’s root). enveloped therefore computes the deduped shown roots, with their objects, before it builds the ruleset; opening the binds stays in bwrap_command.

  • A directory admission D puts a rule on D itself where some bind root’s object lies at or above D, and a rule on every bind root whose object lies inside D: an alias (/alias bound to /tools/sub under Dir(/tools)) and a canonical sub-bind (a ceiling that reads only /tools/sub). Exclusions are subtracted along their spines from each root, their positions read through Excluded::holds as matching reads them (an-exclusion-is-located-in-one-vocabulary). Either way the walk from /tools/sub/prog meets /tools/sub and the envelope’s own directories, never /tools; a nested grant that runs Dir(/tools) under a ceiling that reads only /tools/sub cannot widen reading, so /tools is not shown.
  • Any is the directory /. Under an unrestricted fs it is a rule on /; under a restricted fs, a rule on every bind root remaining after the redundant-bind dedup. When every exclusion is a name veto, nothing is subtracted, so no exec ruleset is built; the scopes stay.
  • Linker candidates are support, admitted unless excluded, not before the table; ral’s pinned inode is no longer admitted at all.
  • Limits, declared: a program created during a launch on the spine of an excluded path runs from the next launch; under Any with exclusions and a restricted fs the envelope’s private /tmp holds no host object, so a program built there does not run; an excluded path hard-linked to an admitted file runs only when the admitted name lies beneath a directory admitted whole; the walk refuses an excluded inode under every name it meets.
  • The walk asks the table alone about each directory and file. Identity is the table’s: an object whose last id is a held leaf L of an exec exclusion matches it at either depth, so a directory is refused by a directory exclusion and a file by either kind. The one object the table does not refuse is a directory whose id is the held leaf of a file exclusion, which never judges a directory; it is governed as the table says, admitted whole where the table allows. Only an unheld, deserialized hold whose inode a directory has since reused reaches that case: ral’s decoder refuses a file key naming a directory, and a held handle pins the inode. The walk keeps no inode set of its own, so it opens nothing the table withholds: each admission is gated by the table, and the kernel ruleset agrees with the grant table and with macOS (landlock/tests.rs, a_directory_a_file_exclusion_holds_is_governed_by_the_table).

Pathname sockets follow stated writes

Every ABI 9 envelope handles REFER | RESOLVE_UNIX, adding EXECUTE where exec is restricted. The parent opens the stated write objects without following symlinks and admits their RESOLVE_UNIX right: a file as itself, its opened inode even when bound at another name; a directory lowered onto the shown bind roots by the same lowered function exec uses. Unrestricted fs adds no socket admissions. Fs denies need no subtraction: bwrap masks them.

  • REFER is restored on the envelope’s /. Handling an fs right denies cross-directory hard links by default; cargo needs them even with exec unrestricted. The payload adds this rule before entering the domain.
  • Mounting is impossible inside every ABI 9 domain. ral builds the ruleset in the parent, lends its descriptor, lets bwrap mount, then enters it. The seccomp deny-set already kills the mount family and refuses CLONE_NEWUSER.
  • No Linux resolver socket is admitted. nss-resolve returns UNAVAIL; the stock resolve [!UNAVAIL=return] dns line continues to DNS, reading resolv.conf and reaching the 127.0.0.53 stub over IP in the shared netns. The nscd client falls back likewise. LLMNR/mDNS through nss-resolve is lost.
  • Sibling launches need a write covering the server socket. A server in the same domain is reachable, but one in a sibling or parent domain is outside it. spawn { postgres -k ./s } followed by psql therefore needs the socket beneath a stated write, as it usually is to permit binding.
  • A write admits a deputy and replacement. A foreign socket beneath a write prefix is reachable; the child can also unlink it and bind its own, intercepting the user’s later clients.
  • Session temp is stated scratch. exarch sets $TMPDIR to $EXARCH_SCRATCH/tmp; the five restrictive bundled profiles grant no shared temp directory. Hardcoded /tmp is the envelope’s per-command tmpfs and is discarded after each command. On macOS it is refused.

When ABI 9 is the floor

The trigger is the oldest supported kernel reporting Landlock ABI >= 9. Until then every pathname socket a bind shows is reachable below ABI 9, even under net: `offline; sockets do not raise the launch floor today.

  • Raise a BASELINE_ABI-style floor for sockets, or refuse restrictive launches below ABI 9; delete the ABI < 9 rows of landlock::plan’s table.
  • Delete this subsection and the declared-limit sentences in grant and capabilities.
  • The deliberately declined interim option is seccomp socket(AF_UNIX) → EACCES. Seccomp sees socket(2)’s args[0], never connect’s path behind a user pointer. Measured sound but coarse, it closes pathname and abstract sockets, including in-envelope AF_UNIX servers and clients; socketpair keeps working.

Where the host refuses a mount, the envelope rebuilds it

Some hosts refuse bwrap a mount it needs. The envelope then builds the same result by hand, or states what it cannot build.

  • A fresh devpts. A rootless container’s mount layer will not give bwrap one, so --dev fails in setup and no Restricted envelope could launch. render_dev lays out --dev’s shape by hand instead: a tmpfs, the device nodes bound in, and a fresh /dev/shm, but no devpts. The refusal is the mount layer’s: on a Fedora (SELinux) host, container_t may not mount devpts (EACCES); --security-opt label=disable lifts it.
  • A fresh procfs. The same runtimes mask /proc, and the kernel then refuses the procfs a pid namespace needs. --unshare-pid is emitted only where the table can be hidden.
  • HostEnvelope learns both with one probe spawn each (authority/sandbox/linux/host.rs).
  • What cannot be rebuilt is stated, not refused. Neither is a restriction a grant names, so the launch runs, and the child sees what it would see unconfined: the container’s own process table (two-enforcers). Running the container --privileged lifts both.
  • No host terminal is reachable by name, in either arm. --dev gives a private devpts; by hand there is none, no /dev/pts and no /dev/ptmx, since the host’s devpts is shared and any view of it leaks host terminals. The child keeps the terminals it inherits as descriptors and allocates none, so a payload that needs a pty (tmux, script, ssh -t) fails by hand. Allocation there was only ever host-conditional (ptmxmode), so no guarantee is lost.
  • The render takes the probed host as data. The argv tests assert both shapes from literals, not from whichever host runs them.
  • Open: such hosts still refuse the read-only rebind of their own locked /etc/hosts and /etc/resolv.conf, by descriptor as by name.

Pinned by authority::sandbox::linux::tests::render::a_host_that_refuses_dev_gets_the_same_shape_by_hand, ::the_by_hand_dev_has_no_devpts, spawn::the_by_hand_dev_serves_a_confined_body and spawn::the_by_hand_dev_reaches_no_host_terminal.

The GPU is shown or masked by name

A frame that leaves the GPU shows its device nodes; one that withholds it shows none. Left on and fs restricted, the render nodes (never card*, which modeset), NVIDIA’s (nvidiactl, nvidia-uvm, nvidia-uvm-tools, nvidia<N>), AMD’s kfd (ROCm compute opens it with renderD*) and WSL2’s dxg are --dev-bind-try’d into the envelope’s /dev after render_dev, with /sys/class/drm, /sys/dev/char and each render node’s device directory read-only. Withheld over an unrestricted fs, /dev/dri is emptied and the other nodes masked unopenable; withheld under a restricted fs, nothing is shown. GpuNodes::discover finds them at each launch: bwrap has no globs, and nvidia-uvm appears on a host’s first CUDA call.

  • Bound by name, the one exception to mounting by handle. /dev and /sys are kernel-owned trees no unprivileged process renames into, so a name there cannot be swapped for a link after rendering, which is the whole risk handles close; render_dev’s own nodes were already bound so.
  • No Landlock rule governs the GPU. The ruleset handles Execute, Refer and, from ABI 9, RESOLVE_UNIX (landlock::plan), not IOCTL_DEV or any read/write right, so opening a device node is decided by what the mounts show and by nothing else: a node absent from the envelope cannot be opened, a node shown can.

Pinned by authority::sandbox::linux::tests::render::a_restricted_envelope_shows_the_gpu_only_where_left_on and ::an_unrestricted_envelope_masks_a_withheld_gpu.

Kernel pseudo-filesystems describe the envelope

A pseudo-filesystem inside the envelope must describe the envelope. One that cannot is a host bind like any other, present only where something needs it.

  • /proc is mounted fresh (--proc /proc) with the pid namespace.
  • /sys has no bwrap operation, and a bound /sys describes the host: its class/net lists the host’s interfaces whatever --unshare-net did, and its class/dmi and bus name the machine. So the Linux Baseline narrows /sys, as it narrows /etc, to what sizes a program: devices/system/cpu and kernel/mm/transparent_hugepage. A grant that wants the rest reads /sys by name.
  • /sys/fs/cgroup would be wrong, not just revealing. Under the cgroup namespace a child’s /proc/self/cgroup reads 0::/, and a runtime that joins that to the host’s tree reads the root’s limits, which are none. cgroup_tree re-roots the tree on ral’s own cgroup, the namespace’s root, which is what a fresh cgroup2 mount inside would show. It does so on both projections, over the projection’s binds. Where the host builds no cgroup namespace (HostEnvelope::private_cgroup), the host’s tree is the true one and is bound as it is.

Pinned by authority::sandbox::linux::tests::render::sys_is_narrowed_to_what_sizes_a_program_and_the_cgroup_tree_is_the_payloads and spawn::a_confined_program_reads_its_own_cgroup_and_none_of_the_hosts_interfaces.

The envelope binary is fixed at boot

The launcher is exactly as trustworthy as the file it is, so ral never picks that file by name at spawn time. At spawn, the only environment in scope is the payload’s, including any PATH override. Command::new("bwrap") would let a within [env: [PATH: …]], or a planted binary earlier on PATH, run code before any confinement.

  • authority::sandbox::boot pins bwrap before any shell exists (authority::sandbox::linux::pin_envelope). It searches the absolute entries of the PATH ral started with, as directories rather than a re-joined string (path::locate_in), and keeps the result as a reexec::Pinned, the same fd pin ral uses to re-exec itself.
  • Every launch execs /proc/self/fd/N. Neither a PATH override nor a replace-by-rename at the pinned path reaches it.
  • In-place rewriting of the pinned inode, the one change a pin by descriptor cannot see, is closed on both sides:
    • for a confined child, by the envelope. Binds::open lends both pins, bwrap’s and ral’s, as Over binds, each read-only by its own descriptor at the name its inode holds now (Pinned::names). They go after the projection’s binds, / wholesale under Unrestricted included, and before the masks. A write gets EROFS, a hard link EXDEV, and a rename or unlink of the mountpoint EBUSY. This is the Linux twin of the write-deny macOS lays on ral’s own file in every profile (seatbelt-profile);
    • for ral’s own writes, by the Guarded verdict (path-judgment).
  • An unlinked pin gets no bind. A replace-by-rename took its name, so there is no name to lock.
  • Still open: another same-uid process, and any later session, since a session cannot vet the enforcer it boots on. Where the pinned bwrap is writable by ral’s uid, the remedy is a root-owned bwrap (the distro package).
  • A host with no bwrap is reported by linux::envelope at the first launch that needs one, and refused as sandbox::unavailable. The launch’s Launcher names the binary only for the wording of a spawn failure.

Pinned by authority::sandbox::linux::tests::render::the_launcher_is_the_pinned_envelope_and_never_a_name, ::the_envelope_binary_is_read_only_inside_every_envelope, trampoline::a_pinned_binary_inside_a_writable_prefix_is_locked and authority::guard::enforce::tests::a_write_onto_a_pinned_binary_is_guarded_before_any_grant_is_consulted.

Exercising the envelope

CI runs both Linux architectures on bare runners, musl target, with RAL_REQUIRE_SANDBOX set. Locally just box lint test runs the same recipes in ral-linux-box under a privileged envelope and a tmpfs /tmp; the policy fixtures outside admitted roots remain outside /tmp.