# Bubblewrap Backend > **Audience:** MXC consumers and developers The Bubblewrap backend provides **unprivileged Linux sandboxing** using [Bubblewrap](https://github.com/containers/bubblewrap) (`bwrap`). It uses Linux user namespaces to create isolated sandbox environments without requiring root privileges or a container runtime. > **Status:** Stable — the default Linux backend. > **Supported contracts (v0.9+):** use `network.egress` / > `network.ingress` and, for proxy requests, `runtimeConfig.networkProxy`. > Versions before `0.9.0-alpha` are rejected; changing only the version of an > old config does not migrate its policy. Legacy `defaultPolicy`, > `enforcementMode`, host lists, `allowLocalNetwork`, and `network.proxy` > are rejected by supported contracts. Typed Rust requests no longer > contain these fields. See [schema migration](../../schema.md). > Bubblewrap still rejects enforceable-looking requests it cannot honor > (such as `ingress.default: "allow"` or direct egress rules combined with a > runtime proxy) before provisioning. An omitted `network` section takes the > directional deny defaults. ## Prerequisites - **Linux** host with kernel 3.8+ (user namespace support) - **x86-64 or AArch64** host. The filter also preserves x32 and i386 compatibility on x86-64, and AArch32 compatibility on AArch64. Platform detection reports Bubblewrap as unavailable on architectures for which MXC cannot generate the required seccomp program. - **Bubblewrap** installed (see [Host tool lookup](#host-tool-lookup) for where MXC looks for it): ```bash # Debian/Ubuntu sudo apt install bubblewrap # Fedora/RHEL sudo dnf install bubblewrap # Alpine apk add bubblewrap ``` The baseline uses `--ro-bind-try`, `--clearenv` and `--seccomp FD`: **bwrap 0.5.0+** is required. Missing deny targets beneath read-only binds additionally require **bwrap 0.11.0+** and unprivileged OverlayFS support. When an overlay is needed, execution rejects a setuid `bwrap` before launch. If the host kernel or source filesystem does not support unprivileged OverlayFS, Bubblewrap can fail with an overlay-mount error such as `Invalid argument`; use a kernel and filesystem that support unprivileged OverlayFS. A missing denied target beneath a read-only source with nested host mounts is rejected before launch because the overlay cannot preserve those mounts. Platform detection probes `bwrap --version` and reports the backend as unavailable — with the detected version — when the host is below that floor. The probe has a 5-second deadline and retains at most 64 KB from each output stream. On timeout, its process group is terminated with `SIGKILL` so wrappers and descendants cannot keep the probe alive. Successful Rust-executor advisory results are cached for the process lifetime; Rust failures are not cached, and execution validation probes again before launch so a changed PATH target cannot reuse an advisory result. The launch then runs the same `bwrap` file that validation checked. The Node SDK caches the complete `getPlatformSupport()` result, including failures, for the module lifetime; restart the Node process after remediating the host. - **Network-enabled private-namespace modes (v0.9+):** `slirp4netns` installed, plus iproute2 `ip`, util-linux `unshare` (with `--map-current-user` and `--keep-caps`), `nsenter`, `iptables`, `ip6tables`, `iptables-restore`, and `ip6tables-restore` for the in-namespace egress and ingress rules, a POSIX `sh` and `sleep` (the supervisor runs as `sh -c`), and the `nf_conntrack` kernel module loaded for the inbound chain's connection-state match (unprivileged Bubblewrap cannot load it on demand). This covers both proxy-only egress via `runtimeConfig.networkProxy` and directional firewall enforcement (egress rules or `egress.default: "allow"`). Both use the same dependency probe and install egress and ingress chains. Ruleless `egress.default: "deny"` instead uses `--unshare-net` alone and needs none of these additional network tools. > `ip6tables` is required to *deny* IPv6, not to carry it. slirp4netns is > launched without `--enable-ipv6`, so the sandbox namespace has no IPv6 > connectivity at all and the v6 rules exist to keep the unmatched family > closed. An IPv6 destination is unreachable even when a rule allows it > (see #955). On a kernel without IPv6 (built without `CONFIG_IPV6`, or > booted with `ipv6.disable=1`) the sandbox cannot open an IPv6 socket, so > the runner returns a warning that it is skipping the v6 rules and installs > only the IPv4 chains. The `ip6tables` tools are still probed there, > because they ship in the same package as `iptables`. ```bash # Debian/Ubuntu sudo apt install slirp4netns util-linux iptables iproute2 # Fedora/RHEL sudo dnf install slirp4netns util-linux iptables iproute # Alpine apk add slirp4netns util-linux iptables iproute2 ``` `iptables` should resolve to the **`nf_tables` backend** (the default on Debian 10+, Ubuntu 20.10+, RHEL 8+, and Alpine). The `iptables-legacy` backend opens `/run/xtables.lock` before touching any table. The rules are installed by an unprivileged supervisor that keeps the caller's uid, so on a stock host with root-owned `/run` it cannot take that lock. `validate` refuses such a host with a message naming the backend rather than letting the supervisor die at the first rule. If configured to use `iptables-legacy`, switch it: ```bash sudo update-alternatives --set iptables /usr/sbin/iptables-nft sudo update-alternatives --set ip6tables /usr/sbin/ip6tables-nft ``` (`iptables-legacy` works only where the lock is writable, for example when running as root. This is a tooling distinction, not a retired schema mode.) Both modes fail explicitly if any of these is unavailable; neither ever falls back to sharing the host network namespace or to running without egress rules. The host must also provide the util-linux `unshare` command with `--map-current-user` and `--keep-caps`. No root is needed: `iptables` runs against the sandbox's own network namespace, where the supervisor holds `CAP_NET_ADMIN`. - User namespaces must be enabled: ```bash # Check: should print "1" cat /proc/sys/kernel/unprivileged_userns_clone ``` ### Host tool lookup MXC finds `bwrap` and the network tools above in this order, both for the availability checks (including the Node SDK's `getPlatformSupport()`) and for the launch: 1. The directories on the calling process's `PATH`, in order. 2. `/usr/local/sbin`, `/usr/local/bin`, `/usr/sbin`, `/usr/bin`, `/sbin`, and `/bin`, in that order. A desktop session or service whose `PATH` leaves out `/usr/sbin` therefore still finds `iptables` there. MXC uses the first executable file with the tool's name and launches it from the path its checks approved. If that file cannot start, is too old, or uses an iptables backend the sandbox cannot drive, the request fails; MXC does not try another copy. The error names the file for the network tools, and for a `bwrap` that is not executable, is missing its interpreter or loader, or is too old. Empty and relative `PATH` entries are ignored, so a tool is never taken from the current directory. The lookup applies only to the host programs that set up the sandbox. The command inside the sandbox gets its own `PATH`; see [Process environment](#process-environment). ## Quick Start ```json { "version": "0.9.0-alpha", "containment": "bubblewrap", "process": { "commandLine": "echo 'Hello from Bubblewrap sandbox'" } } ``` Run with: ```bash lxc-exec --config bubblewrap_hello.json ``` Or via base64: ```bash lxc-exec --config-base64 "$(base64 -w0 bubblewrap_hello.json)" ``` ## How It Works Bubblewrap creates a namespace-isolated process by: 1. Unsharing user, PID, IPC, and UTS namespaces (`--unshare-*`) 2. Bind-mounting a **minimal deny-by-default baseline** read-only into the sandbox (`/bin`, `/sbin`, `/lib*`, `/usr/bin`, `/usr/sbin`, `/usr/lib*`, `/usr/libexec`, `/usr/share`, `/etc`, plus a read-only copy of the resolver configuration when its target is in a supported resolver location). Everything else on the host — including the caller's `$HOME`, `/root`, `/opt`, `/var`, `/sys`, and `/run/user/` — is invisible inside the sandbox. 3. Layering filesystem policy overrides (read-write, read-only, denied paths) 4. Setting up minimal `/dev`, `/proc`, and `/tmp` 5. Installing a seccomp filter that permits `socket()` and `socketpair()` only for Unix-domain, IPv4, IPv6, and netlink address families, and disables io_uring 6. Clearing the environment and applying only requested variables 7. Executing the command via `sh -c` The sandboxed process runs as a child of `bwrap` and dies automatically when execution completes — no container lifecycle management required. `bwrap` runs with `--die-with-parent`, whose parent-death signal Linux delivers when the *thread* that forked `bwrap` exits. MXC therefore forks `bwrap` from a dedicated thread that lives as long as the process, so a sandbox started from a pooled or short-lived thread (for example a Tokio `spawn_blocking` worker) survives that thread and dies only with the embedding process. The address-family filter is always active. Attempts to create VSOCK, packet, or other unlisted socket families fail with `EPERM`. Because io_uring can create sockets from submission-queue entries that seccomp cannot inspect, the filter also makes `io_uring_setup`, `io_uring_enter`, and `io_uring_register` fail with `ENOSYS`; runtimes that probe for io_uring fall back to their non-io_uring paths. Other system calls are not restricted by this filter. Filter construction, writing, or descriptor inheritance failures abort the launch instead of running without the filter. On x86-64 hosts, native and x32 workloads retain their normal syscall ABI, and i386 workloads using the direct `socket` and `socketpair` syscalls receive the same family filtering. The legacy i386 `socketcall` interface passes the socket arguments through a pointer that seccomp cannot inspect, so its socket-creation and socket-pair subcalls fail with `EPERM`; its other subcalls remain available. On AArch64 hosts, native and AArch32 direct socket syscalls receive the same family filtering. MXC supplies one generated program through the legacy `--seccomp FD` option. Bubblewrap rejects combining that option with `--add-seccomp-fd`, so any future Bubblewrap syscall policy must be composed into this generated program rather than passed as a second filter descriptor. ### Terminal isolation CLI execution and SDK execution with pipes do not share the caller's controlling terminal. This prevents `TIOCSTI` input injection into the host terminal even on hosts that permit that ioctl. Redirecting standard input and output alone does not separate the controlling terminal. SDK execution with pipes creates a new session before starting Bubblewrap, keeping its monitor and namespace init in the same process group. Cancellation can therefore terminate that group even before Bubblewrap enables its parent-death cleanup. CLI execution uses `--new-session` instead. CLI execution still inherits its standard input, output, and error descriptors, but the workload cannot reopen the host terminal through `/dev/tty` or use it for terminal job control. SDK inherited-stdio execution (`spawn_with_extended_options` with `SpawnStdio::Inherit`) behaves the same way. For programs that need a controlling terminal, use the SDK's PTY execution API, which allocates a separate terminal and supports resizing and merged output. ### Deny-by-default filesystem The baseline mirrors the macOS Seatbelt backend's `(deny default)` posture: the sandbox can read the dynamic linker, libc, system tools, and system configuration — and **nothing else** — until the caller opts in via `readonlyPaths` / `readwritePaths`. To make a host directory visible inside the sandbox, list it explicitly: ```json { "filesystem": { "readonlyPaths": ["/home/alice/project", "/usr/local"], "readwritePaths": ["/tmp/workspace"] } } ``` Common consequences of this default: - `$HOME` (e.g. `~/.aws/credentials`, `~/.ssh/id_*`, browser cookies) is not readable from the sandbox. - `/opt` and `/usr/local` tooling is not on PATH; list either path under `readonlyPaths` if the script depends on it. - `working_directory` must live under the baseline or a policy path — a `cwd` of `~/project` without a matching `readonlyPaths` entry will fail. At launch, Bubblewrap retains a mount-configuration hint for SDK callers, which `lxc-exec` also prints to stderr, when an explicit absolute cwd has no apparent overlap with known mount destinations. This compares path spellings without inspecting the host cwd or policy paths, so symlinks or runtime mount behavior can make the hint inapplicable. Check `readonlyPaths` or `readwritePaths` for a containing directory. Ambiguous paths (including `..` and paths near policy mounts) are left to Bubblewrap; silence does not prove a cwd is accessible. The hint does not change execution or replace Bubblewrap's error. - The sandbox can read resolver configuration on systemd-resolved, NetworkManager, resolvconf, and WSL hosts without exposing their runtime directories. MXC copies the regular file used by `/etc/resolv.conf` from `/run/systemd/resolve`, `/run/NetworkManager`, `/run/resolvconf`, or `/mnt/wsl/resolv.conf`, and recreates only the links needed to reach it. Relative links and paths through the sandbox's `/var/run -> /run` link are supported. The copy is read-only and does not track later host updates. Filesystem-policy mounts still take precedence, including explicit grants to custom resolver targets. An ancestor denial still applies when a resolver directory is a symlink to another location. Grants through resolver symlinks and sibling-file grants retain their declared access; the read-only resolver copy does not make writable siblings read-only. Child denials and read-only restrictions also take precedence when a writable parent is named through an alias and the child uses its physical path. Resolver snapshots use sealed, anonymous file descriptors rather than temporary host pathnames. Bubblewrap copies them into private read-only directories before applying filesystem policy. The default mounts exclude host resolver sockets, including `io.systemd.Resolve`, in every network mode. An unavailable or invalid resolver produces a warning rather than a directory-wide fallback; an absent resolver file is allowed. NSS configurations using `nss-resolve` need a `dns` fallback when the host daemon's socket is unavailable. Hosts that point `/etc/resolv.conf` at another custom location still need the resolver file listed in `readonlyPaths` unless it is already covered by the system baseline. Bubblewrap retains a mount-configuration hint for SDK callers, which `lxc-exec` also prints to stderr, when a direct, absolute resolver symlink target has no overlapping known mount destination. The check reads the link but does not resolve or stat its target or policy paths; a missing file or symlink alias can make the hint inapplicable. Check the link and consider listing the resolver file in `readonlyPaths`. Relative targets, uncertain mounts, and synthetic destinations such as `/tmp` and `/var/run` suppress the hint. Silence does not prove DNS is available; the hint never changes mounts or the run's outcome. Reading the file is not the same as reaching the nameserver it names — see [Loopback resolvers](#loopback-resolvers). Files in `/etc` that contain secrets (`/etc/shadow`, `/etc/sudoers`, `/etc/ssh/ssh_host_*_key`) are mode `0400` / `0640` `root` and remain unreadable to a non-root caller — user-namespace UID mapping does not bypass kernel DAC. ## Configuration Bubblewrap uses the shared cross-backend configuration fields. No backend-specific config block is needed. ### Process environment The host environment is never inherited — the sandbox is built with `--clearenv`, so host secrets can't leak into untrusted code. **From schema 0.9** the child gets a default block of `PATH` (`/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin`), `TERM` (`xterm-256color`), and — only when `process.cwd` resolves one — `HOME` (the directory the child is started in): | `process.env` | `inheritDefaultEnv` | Result | | --- | --- | --- | | omitted | — | the default block | | `[]` | — | nothing at all | | `["FOO=bar"]` | `false` (default) | `FOO` only — **no `PATH`** | | `["FOO=bar"]` | `true` | the default block plus `FOO`; a same-named entry wins | > ⚠️ **`HOME` is only set when `process.cwd` is supplied.** MXC has no private > directory it can guarantee otherwise: a `readwritePaths` grant is bind-mounted > after `--tmpfs /tmp` and therefore replaces it, so `/tmp` may be the host's > shared directory. Pass `"HOME=…"` in `process.env` if your command needs it. > ⚠️ **`HOME` is the working directory.** Dotfiles inside it — `.gitconfig`, > `.npmrc`, `.curlrc`, `.config/*` — are therefore read as *user-level* tool > configuration, not just project input. Pass `"HOME=…"` to point elsewhere > when the workspace is untrusted. The table is the environment MXC hands the child. Bubblewrap runs the workload under the host's `/bin/sh`, and a shell started without these assigns its own: dash (Debian, Ubuntu) fabricates a `PATH` that happens to equal the default block's value, while bash (RHEL) fabricates a shorter `/usr/local/bin:/usr/bin` plus `TERM=dumb`. So neither reads back as empty from inside the workload, whatever MXC passed. ### Filesystem Policy Policy validation and the resolution of denied and granted paths use the shared [filesystem probe deadlines](../../schema.md#filesystem-probe-timeouts). A stalled probe rejects startup rather than leaving a policy check unenforced. | Field | bwrap Mapping | Description | |-------|---------------|-------------| | `readwritePaths` | `--bind ` | Read-write bind mount (overrides base RO) | | `readonlyPaths` | `--ro-bind` or `--ro-overlay` | Read-only; private missing deny mountpoints require `TMPDIR` outside the source | | `deniedPaths` (directory or missing path) | `--tmpfs `, then `--remount-ro ` | Masked with a read-only tmpfs | | `deniedPaths` (file) | `--ro-bind /dev/null ` | Masked with `/dev/null` (a tmpfs would turn the file into a directory) | A denied path is classified by its own on-disk type (via `symlink_metadata`, no symlink-follow): a directory is masked with a read-only `--tmpfs`, while a regular file is masked by binding `/dev/null` over it (masking a file with a tmpfs would replace it with an empty *directory*, changing its type). Paths that cannot be stat'd (missing/unreadable) fall back to a read-only `--tmpfs`. The masks are remounted after policy mounts are created, so a more specific allowed child remains accessible with its own permissions. When a missing denied path needs a private overlay, the executor masks the overlay backing directory at its normal path and at any writable bind-mount alias found in `/proc/self/mountinfo`. The mount list is read with the filesystem-probe deadline and bounded to 1 MiB and 4096 entries; startup fails closed if it cannot be read or parsed. If the read-only source contains a nested host mount, startup also fails before the workload starts rather than exposing the directory underneath that mount. **Denied paths are resolved through symlinks before masking.** bwrap creates a mask by mounting over the destination path, and it cannot create a mount point when **any** component of that path — the leaf itself *or* an ancestor directory — is a pre-existing host symlink whose parent is bound into the sandbox (the mount then resolves through the host symlink and fails with `ENOENT`, aborting the sandbox). So both `/a/link` (symlinked leaf) and `/a/link/secret` (symlinked ancestor) would abort. A `deniedPaths` entry is therefore rewritten to its real filesystem path before mounting — canonicalizing the deepest existing ancestor (following symlinks at every level) and re-appending any not-yet-created trailing components — so the mask lands on the real object and its file/directory type is classified from that target. Relative entries are resolved from MXC's working directory. Dangling links, loops, and other paths that cannot be resolved fail before the sandbox starts. **Grants are mounted at their real paths too.** `readwritePaths` and `readonlyPaths` entries are resolved the same way, so the more specific entry wins whichever spelling the policy or the workload uses: a denied or read-only path inside a grant applies, and a grant inside a denied directory stays visible. Each host symlink that an entry is named through is recreated inside the sandbox, so the caller's spelling still works, including as `process.cwd`. For example, when `/home/alice/app` is a symlink to `/data/repos/app`, this policy mounts `/data/repos/app`, masks `/data/repos/app/.env`, and links `/home/alice/app` to `/data/repos/app`, so `.env` is hidden under both paths: ```json "filesystem": { "readwritePaths": ["/home/alice/app"], "deniedPaths": ["/home/alice/app/.env"] } ``` A symlink that is already visible through another mount, such as one inside a granted directory, is used as it is, and any other symlinks it leads through are recreated as well. Where the sandbox has its own directory at the symlink's path, such as its private `/tmp` on a host whose `/tmp` is a symlink to `/var/tmp`, the sandbox keeps that directory and recreates the next part of the path inside it, so a grant of `/tmp/project` is still reachable as `/tmp/project`. A grant of that whole `/tmp` replaces the private `/tmp` with the symlink, so `/tmp` in the sandbox is the host's `/var/tmp`. Where the sandbox has its own symlink at that path pointing somewhere else, such as its `/var/run -> /run` on a host whose `/var/run` points elsewhere, the next part of the path is recreated where the sandbox's symlink leads. A directory that a path or symlink climbs out of with `..`, such as `staging` in `/data/staging/../app`, is created empty inside the sandbox if it is not already there, so the path still works without showing that directory's contents. A symlink that cannot be recreated at all, such as one under `/dev` or `/proc`, leaves paths through it unavailable inside the sandbox. Whenever a spelling is unavailable, Bubblewrap reports a warning naming the real path to use. A grant that cannot be resolved, such as a dangling symlink or a symlink loop, stops the sandbox from starting. Only symlinks are followed. A hard link, or a host bind mount that shows the same files under a second path, stays a separate path inside the sandbox: a rule on a file or directory inside one of them does not apply to the same files reached through the other. On merged-/usr hosts, baseline entries such as `/bin`, `/sbin`, and `/lib*` are symlinks into `/usr`. The sandbox recreates each one as a relative symlink to the mounted directory instead of mounting that directory a second time, so denying `/usr/bin/cat` or `/bin/cat` hides the file under both spellings. If one of these symlinks cannot be followed, for example because of a permission error or a symlink loop, the sandbox does not start. A baseline symlink whose target lies outside the baseline is still mounted at its own path, where a mask on the target's real path does not apply. Example: ```json { "version": "0.9.0-alpha", "containment": "bubblewrap", "process": { "commandLine": "cat /data/input.txt && echo result > /workspace/output.txt" }, "filesystem": { "readonlyPaths": ["/data"], "readwritePaths": ["/workspace"], "deniedPaths": ["/secrets"] } } ``` ### Network Policy All supported exact requests use directional `network.egress` and `network.ingress`. Both ingress controls default to `deny` when omitted. The JSON objects below are network fragments to place in a v0.9+ request. **Full block** (ruleless `egress.default: "deny"`, no runtime proxy) uses `--unshare-net` for complete network namespace isolation. The sandbox gets a private network stack with only its own loopback (bwrap brings `lo` up), so nothing outside the sandbox is reachable and nothing outside can reach in. This needs no root or `slirp4netns`. ```json { "network": { "egress": { "default": "deny" }, "ingress": { "default": "deny", "hostLoopback": "deny" } } } ``` **Address filtering** (`egress.allow` / `egress.deny`) puts the sandbox in a private, slirp-backed network namespace and programs its rules there from a supervisor holding `CAP_NET_ADMIN` inside an unprivileged user namespace. **No root required**; the sandbox drops `CAP_NET_ADMIN` before the workload starts, so it cannot undo the rules. Rule addresses must be **IP literals or CIDR blocks**; a DNS name is rejected at validation time rather than resolved on the caller's behalf. The backend does not resolve, because the sandbox resolves names itself and a lookup that disagreed with the one behind the rules would hand the workload an address the chain never authorized. ### Loopback resolvers Every mode runs the sandbox in its own network namespace, so a nameserver on the host's loopback — `systemd-resolved`'s stub at `127.0.0.53`, a local `dnsmasq` at `127.0.0.1` — names an address that belongs to the sandbox's own empty loopback. Making the resolver file readable does not make that address reachable, and names do not resolve through it. Under **address filtering**, MXC therefore replaces the sandbox's resolver with slirp's built-in forwarder, `10.0.2.3`. libslirp rewrites a query sent there to the first IPv4 nameserver in the *host's* `/etc/resolv.conf` and sends it from the host's network namespace, which is what puts the host's stub back in reach. `search`, `domain`, `sortlist`, and `options` are carried over unchanged, since they decide which names resolve. Comments and unrecognized lines are not: the replacement can land on a path the filesystem policy never granted, so only the resolver's own behavior crosses that boundary. The replacement applies only when the host's own resolvers are **all** loopback addresses and **at least one** is IPv4, so it cannot redirect name resolution that already works, and it never applies when slirp has no IPv4 nameserver to forward to. The file is mounted over the path the `/etc/resolv.conf` symlink chain ends at — resolved through every component, not just the leaf, because bwrap cannot create a mount point under an unresolved symlink and aborts the sandbox when asked to. **The pin never costs you a sandbox.** It improves on a resolver the sandbox already cannot reach, so every failure gives up the pin rather than the run: a resolver path that cannot be followed, one the filesystem policy denies, a resolver file that exists but cannot be read, and a failure to write the replacement all leave the sandbox exactly as it would have started without this feature, each with a warning naming the cause. A host with no `/etc/resolv.conf` at all is silent — there is no loopback stub to rescue. A policy that names `/etc/resolv.conf` (or the path its symlink chain ends at) in `readonlyPaths` / `readwritePaths` is supplying its own resolver, and the sandbox keeps that one — with a warning, because a resolver naming only loopback nameservers is unreachable from the sandbox whoever mounted it. This includes file grants through intermediate resolver-directory symlinks. Listing an ancestor such as `/etc` is not treated as a choice about the resolver. Two cases are deliberately untouched: - **`runtimeConfig.networkProxy`** — a proxy-only chain opens no port 53 and the proxy resolves on the workload's behalf. - **Ruleless `egress.default: "deny"`** — the sandbox has no connectivity at all, so it has nothing to resolve with. Under `egress.default: "deny"` *with* rules, the chain's terminal verdict still governs: a query to `10.0.2.3` is dropped unless a rule permits it. MXC warns at launch when it pins the resolver and the chain admits nothing to `10.0.2.3:53`, naming the rule to add — allow `10.0.2.3/32` on port 53 with protocol `any`. Both protocols are needed: a resolver falls back to TCP for an answer that does not fit a datagram, and `options use-vc` makes it use TCP for everything. The rule is not added automatically: the chain is the caller's policy. > ⚠️ slirp's forwarder reaches the host's resolver by design, and the chain's > `-d 10.0.2.2/32 -j DROP` rule — which closes the sandbox's path to host > loopback services — does not cover it. Name resolution is the one host > loopback service an address-filtered sandbox can reach. **IPv6 rules are filtered, but IPv6 traffic has nowhere to go.** The two are separate concerns and only the second is missing. Filtering works: an IPv6 rule programs `ip6tables`, and the terminal verdict of the unmatched family follows `egress.default`, so an IPv4-only allow rule under `deny` does not leave IPv6 open. What the sandbox lacks is IPv6 *connectivity* — slirp4netns is launched without `--enable-ipv6`, so the namespace has no IPv6 route at all (see #955). The consequence is one-sided: an IPv6 **block** is already satisfied, while an IPv6 **allow** grants nothing in practice, because the destination stays unreachable regardless of the rule. MXC emits a warning naming those allowed destinations rather than refusing them, since the posture fails closed. An IPv4-mapped address such as `::ffff:203.0.113.5` is programmed as IPv4: Linux sends a genuine IPv4 packet for one, so an `ip6tables` rule naming it would never match and a directional deny rule under `egress.default: "allow"` would fail open. A mapped CIDR is translated the same way — the mapped range is the last 32 bits of `::ffff:0:0/96`, so a `/96 + n` prefix becomes a v4 `/n`. An IPv6 block **shorter** than `/96` that contains `::ffff:0:0/96` is **rejected** rather than programmed. CIDR blocks nest or are disjoint, so such a block always swallows the mapped range whole, and neither available reading is safe to apply silently: leaving it on `ip6tables` unenforces the mapped half (the same fail-open the translation above exists to prevent), while projecting it onto IPv4 would always widen it to `0.0.0.0/0` — turning a deny rule for `::/0` from "block all IPv6" into "block all IPv4 as well". The rejection asks the caller to write the IPv4 side explicitly. Blocks that do not contain the mapped range, such as `2001:db8::/32`, are unaffected. An explicit `egress.deny` rule outranks a broader `egress.allow` rule: denies are installed ahead of allows in a first-match chain. ```json { "network": { "egress": { "default": "deny", "allow": [{ "to": [{ "cidr": "203.0.113.0/24" }] }], "deny": [{ "to": [{ "cidr": "203.0.113.4/32" }] }] }, "ingress": { "default": "deny", "hostLoopback": "deny" } } } ``` **Open external egress** (`egress.default: "allow"` with no rules or proxy) also uses the private slirp-backed namespace. Its egress chain defaults to `ACCEPT`, but drops host-loopback traffic first. It never shares the host network namespace; ingress and host loopback still default to deny. #### Ingress and host-loopback isolation The retired `allowLocalNetwork` field has no v0.9 spelling. Use `network.ingress.default` to express unsolicited inbound policy and `network.ingress.hostLoopback` for the bidirectional host-loopback path. Bubblewrap currently honors only `deny` for either control. An `allow` value is rejected before sandbox creation: slirp has no host-to-sandbox port forwarding, so no inbound-accepting posture could be delivered. The sandbox's own loopback remains usable by its processes for `bind()` and `listen()`; that does not open an inbound path from the host. Under slirp, host-loopback denial also blocks container-to-host traffic at `10.0.2.2`, ahead of any outbound allow rule. The only exception is the configured runtime proxy endpoint, which proxy-only egress opens on that gateway. #### Inbound is closed by the namespace, and by a chain The v0.9+ proxy and firewall-enforced modes also install an `MXC_INGRESS` chain hooked into `INPUT`, for both families: ``` -i lo -j ACCEPT -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT -m conntrack --ctstate NEW -j DROP -j DROP ``` Be honest about what this buys. It is **not** new protection: nothing outside the sandbox can reach in already, because the runner configures no port forwarding into the namespace, so there is no path for an inbound packet to arrive on. The chain is defense in depth against a future change that adds one, and a defense-in-depth implementation of `ingress.default`. The terminal `DROP` is deliberately independent of `egress.default`, which governs outbound traffic only — an open outbound posture must not open inbound as a side effect. The `ESTABLISHED,RELATED` accept is not optional. A terminal `INPUT` drop applies to reply packets too, so without it the sandbox would lose all networking rather than gain an inbound restriction. That connection-state match requires `nf_conntrack` on the host. Unprivileged Bubblewrap cannot `modprobe`, so if the module is not already loaded the `iptables-restore` transaction fails, iptables rolls the whole table back, and the supervisor aborts before releasing the workload. The failure is loud and fail-closed by construction, not a silently unenforced sandbox. No separate probe is performed: the transaction is a stricter check than probing the userspace extension would be, because it exercises the match in the actual namespace. No RFC 4890 ICMPv6 exemptions are emitted. `slirp4netns` runs without `--enable-ipv6`, so the namespace has no IPv6 for them to govern; they must be added in the same change that enables it. #### Directional policy (`network.egress` / `network.ingress`) Schema `0.9.0-alpha` uses an explicit `egress` and `ingress` section instead of the retired `defaultPolicy` / `allowedHosts` / `blockedHosts` fields. An `0.9.0-alpha` config carrying a legacy field fails parsing; a config declaring an earlier version is refused as an unsupported contract version before its network section is read. ```json { "network": { "egress": { "default": "deny", "allow": [ { "to": [{ "cidr": "1.1.1.1/32" }], "ports": [{ "protocol": "tcp", "port": 443 }] } ] }, "ingress": { "default": "deny", "hostLoopback": "deny" } } } ``` Egress lowers into the namespace-local iptables chains described above. The supervisor holds `CAP_NET_ADMIN`, the sandbox drops it, and no root is required. Addresses are IP literals or CIDRs only. An `except` list on a rule is lowered by CIDR subtraction into the remaining covering blocks, so `allow 0.0.0.0/0 except 1.1.1.0/24` becomes a set of accepts that provably omit the carve-out rather than an accept followed by a hoped-for later deny. **Protocol support.** `ports[].protocol` accepts `tcp`, `udp`, `icmp`, and `any`. What Bubblewrap actually enforces is bounded by its *transport*, not by its rule engine: every mode that installs egress rules puts the sandbox behind `slirp4netns`, a userspace network stack that carries **TCP, UDP, and ICMP echo only**. No other IP protocol — SCTP, DCCP, GRE — has a path out of the namespace, whether or not a rule names it. | Selector | Rules emitted | Notes | |---|---|---| | `tcp` | `-p tcp` | | | `udp` | `-p udp` | | | `icmp` | `-p icmp` (IPv4) / `-p icmpv6` (IPv6) | Expands by destination address family. | | `any`, no `port` | no `-p` match at all | Matches every protocol, ICMP included. | | `any` with a `port` | `-p tcp` and `-p udp` | ICMP is omitted: it carries no port numbers for a port-scoped rule to name. | The `any` selector covers at minimum TCP, UDP, and ICMPv4/6. ICMPv6 is satisfied vacuously: `slirp4netns` is launched without `--enable-ipv6`, so the namespace has no IPv6 route. The `ip6tables` rules render correctly, but nothing traverses them. **Mode selection.** Directional never resolves to the shared host namespace: | Directional policy | Resolved mode | |---|---| | runtime proxy with ruleless `egress.default: "deny"` | proxy-only | | ruleless `egress.default: "deny"` | isolated (`--unshare-net`) | | anything else — rules present, or `egress.default: "allow"` | firewall-enforced (private namespace) | An open outbound posture therefore becomes an accept-all chain **inside a private namespace**, not a shared host namespace. That is deliberate. The parser fills `network.ingress` unconditionally on the directional path — including when the config has no `network` section at all — and there is no `_specified` twin to distinguish a defaulted `ingress.default: "deny"` from a written one. Sharing the host namespace would leave that deny unenforceable, and it could not be refused without also refusing every legitimate "allow all outbound" config. Choosing the private namespace keeps the inbound half true for the cost of a slirp hop. A config with **no `network` section** also gets a synthesized directional default-deny policy. It runs isolated, with ingress and host loopback denied; omitting ingress never requests a shared host namespace. **What the backend refuses.** Bubblewrap declares support for `egress.default`, `egress` rules, `ingress.default`, `ingress.hostLoopback`, and `runtimeProxy`. Declaring the two inbound features means the backend *understands* those fields — not that it honors both of their values. Only the deny posture is reachable, so the allow posture is refused rather than accepted and dropped on the floor: | Rejected | Why | |---|---| | `ingress.default: "allow"` | slirp4netns installs no route into the namespace, and the schema carries no port list with which to forward one. Nothing would arrive, so "allow" would be a lie | | `ingress.hostLoopback: "allow"` | the inbound half needs the same port forwarding `ingress.default: "allow"` lacks. Granting only the outbound half would honor half a bidirectional field under its full name | | `egress.default: "allow"` or direct egress rules combined with a runtime proxy | proxy-only egress opens the proxy endpoint alone; a simultaneous open default or rule list would be silently discarded and is refused | **What the deny postures actually do.** In proxy-only and firewall-enforced modes, `ingress.default` installs the `MXC_INGRESS` chain on `INPUT`. Ruleless egress deny instead isolates the namespace, leaving no external inbound path. `ingress.hostLoopback` is bidirectional, so its deny also closes container-to-host traffic under slirp at gateway `10.0.2.2`. That drop is lowered *ahead* of every caller rule: a broad allow, including `0.0.0.0/0`, would otherwise win. An omitted `ingress` section enforces the same deny, since deny is the schema's default rather than an absence of policy. This gateway drop is IPv4 only — slirp gives the sandbox no IPv6 route to the host. Proxy mode is the defined exception. The proxy is reached at the gateway `10.0.2.2:`, which *is* host loopback, so its chain opens that single TCP endpoint and drops the rest of the gateway. The supported proxy-only policy permits this exception: the endpoint named by `runtimeConfig.networkProxy` is allowed independently of `ingress.hostLoopback`, and no other host-loopback path is opened. A proxy config that states — or defaults to — `deny` therefore gets the posture it writes, since the deny still covers every host-loopback path but that endpoint. `ingress.hostLoopback` is not consulted there — `EgressPlan::for_proxy` builds that chain, not the directional builder that lowers the drop — but the observed result still matches the requested network policy. The declaration and these refusals must ship together — declaring the inbound features without them would be a fail-open. A unit test asserts exactly that pairing, driven through `validate()` rather than the gate function, so deleting the wiring fails the test. **Declaration alone is not evidence.** `hostLoopback` was declared, accepted, and completely unenforced for its whole first life: egress to `10.0.2.2` was open on every directional config, and the end-to-end suite used exactly that address as its "reachable" target — so the tests were passing *because of* the bug. Acceptance proved only that shared validation did not refuse the field. Each declared bit therefore carries an **enforcement probe** in `every_network_policy_support_bit_is_a_deliberate_decision`: the probe flips the field in a copy of the request and requires the rendered `iptables-restore` payload to change. A bit whose field can be flipped with no effect on the chain is over-declared and fails there. Reverting the host-loopback drop reproduces the original bug as a test failure. `runtimeProxy` is declared. The parser normalizes `runtimeConfig.networkProxy` into `policy.network_proxy`, restricted to a loopback endpoint and accepted only alongside `egress.default: "deny"` with no direct rules. That is the proxy-only posture this backend enforces. The end-to-end test runs the supported proxy configuration with ingress denial both omitted and explicit, checks each against expected proxy-only verdicts, and compares the two. A direct-egress probe targets a live listener on a different port from the proxy, so an unreachable external host cannot falsely pass the test. `proxyPeerIdentity` stays undeclared: it is a ProcessContainer concept with no Bubblewrap equivalent, so shared validation refuses it here. Because the bits are a hand-written declaration with nothing deriving them from the fields the backend actually consumes, a bit that is simply never added is indistinguishable from one that was considered and refused — both surface as the same clean rejection. `runtimeProxy` sat undeclared for exactly that reason while the proxy machinery behind it was already complete. A unit test now enumerates every `NetworkPolicySupport` bit and fails if a newly added one is left uncategorized, so the decision can no longer be made by omission. ### Process Settings Standard `process` fields work as expected: ```json { "process": { "commandLine": "python3 script.py", "cwd": "/workspace", "env": ["PATH=/usr/bin", "HOME=/tmp"], "timeout": 30000 } } ``` ## Network proxy (private namespace, unprivileged) Bubblewrap supports an **unprivileged, cooperative network proxy** that routes cooperating clients through the endpoint named by `runtimeConfig.networkProxy`. Any hostname filtering belongs to that external proxy, not MXC host lists. The workload runs in a private network namespace and reaches the proxy through rootless `slirp4netns` routing. This requires no root privileges. All supported exact requests use this private-network behavior; a missing or pre-v0.9 version is rejected, not routed to the old shared-host-network behavior. ### How it works 0. Before a launch, the runner checks the host tools this mode depends on — `slirp4netns`, `unshare` (checked for `--map-current-user` and `--keep-caps`), `sh`, `nsenter`, `ip`, `iptables`, `ip6tables`, `iptables-restore`, `ip6tables-restore`, and `sleep`, found as described in [Host tool lookup](#host-tool-lookup) — so a host that is missing one fails immediately with a message naming it, rather than partway through supervisor startup. For the `iptables` family presence is not enough: the probe also reads the backend from the version banner and refuses a legacy backend whose `/run/xtables.lock` this user cannot open, because the unprivileged supervisor would otherwise die at the first rule. Each probe is bounded by a short timeout, and runs in its own process group so a backgrounded descendant that inherited the probe's output cannot outlive it: a wedged binary is reported as hung and named, instead of stalling every proxy-mode execution on the host indefinitely. A successful probe is reused for the life of the process while the lookup keeps selecting the same paths; a different path is probed again before it runs, and failures are not reused, so installing the missing tool takes effect without a restart. The supervisor runs each tool from the path the probe checked. Standalone validation and dry runs also try creating disposable user and network namespaces and running `sh`. A launch does not repeat that allocation: it checks namespace availability when it starts the supervisor and Bubblewrap. 1. The caller starts the proxy and names its loopback endpoint with `runtimeConfig.networkProxy`. The parser admits `localhost`, `127.0.0.1`, or `[::1]`; Bubblewrap rejects `[::1]` because its gateway reaches only IPv4. Use a proxy listening on `127.0.0.1` or `localhost`. 2. The runner creates a same-UID user-namespace supervisor, starts Bubblewrap with `--unshare-net`, and keeps the workload behind a startup barrier. 3. The supervisor waits for Bubblewrap's loopback to be up with `127.0.0.1/8`, querying the child network namespace with `nsenter` and `ip`. The child-PID notification is not a setup-ready signal: starting slirp before loopback is initialized can create the address before Bubblewrap's exclusive address request and fail startup. Query errors fail startup; the wait shares the existing network-startup deadline. Only then does the supervisor attach `slirp4netns` to the private network namespace. Host-loopback proxy endpoints are presented to the sandbox through slirp's `10.0.2.2` host gateway. Once slirp is up, the supervisor programs a default-DROP `MXC_EGRESS` chain into that namespace via `nsenter`, permitting only loopback and the proxy endpoint (IPv6 gets a DROP-only chain, or no chain when the kernel has no IPv6 to carry), plus a default-DROP `MXC_INGRESS` chain on `INPUT` (see [Inbound](#inbound-is-closed-by-the-namespace-and-by-a-chain)). Each family's whole table — both chains, their rules in order, the terminal verdicts and the `OUTPUT` / `INPUT` hooks — is applied with `iptables-restore` rather than one `iptables` invocation per rule. One restore is one bounded netlink transaction, so a table too large for it is split across numbered payload files against a byte budget and applied in order with `-n`, so each later transaction appends. Both built-in hooks ride in the *last* transaction of a family, so a hook is never live over a half-built chain and a partial apply leaves the policy unhooked rather than half-enforced. The workload is released only after every transaction is applied, so it can never run with egress open. A failure to program any rule aborts startup. The runner terminates Bubblewrap and its blocked sandbox child while the startup barrier is still held, then reaps the launcher, cleans up the network helpers, and returns the setup error. This also applies to create-and-run execution, streaming, and PTY execution in both proxy-only and firewall-enforced modes. Bubblewrap joins the supervisor's user namespace (`--userns`) rather than creating its own, so the sandbox lives in the namespace that owns the rule-bearing network namespace. This relies on Bubblewrap dropping capabilities in the sandboxed process — the runner passes no `--cap-add` — which is what prevents the workload from holding the `CAP_NET_ADMIN` needed to flush the chain. 4. The command builder sets `HTTP_PROXY`, `HTTPS_PROXY`, `ALL_PROXY`, `FTP_PROXY`, and their lowercase variants inside the sandbox via `bwrap --setenv` (caller-supplied values for these keys, including `NO_PROXY` / `no_proxy`, are stripped before injection). The runner deliberately does **not** set `NO_PROXY`, because exempt destinations would bypass the configured proxy policy. 5. Cooperative tools (curl, wget, Python `requests`, Node `https`, etc.) honor the env vars and traffic flows through the external proxy, which applies its own host restrictions if configured. Non-cooperating clients are not merely unrouted — their direct traffic is dropped by the egress chain. ### Losing the network provider mid-run `slirp4netns` carries the sandbox's only route, so a slirp that dies under a running workload leaves the sandbox running against a dead network: every connection fails with a generic transport error, and the run is attributed to whatever the workload reported. Two checks close that, and both apply to firewall-enforcement mode as well, since it stands up the same supervisor and the same slirp. **Before the workload starts.** Readiness is latched, not revoked — it says slirp *came up*, not that it is still up — so it can already be stale by the time the startup gate opens. The supervisor is re-checked immediately before the gate is released. Any exit fails the run, including a successful one: slirp's exit code says nothing about whether the sandbox still has a route. **For the lifetime of the workload.** The supervisor inherits the write end of a pipe nothing ever writes to, and slirp inherits it in turn; the runner keeps only the read end. That descriptor reaches EOF when *both* have exited, which is what separates a dead network from an orphaned slirp still carrying traffic after its supervisor was killed. A monitor thread in the executor watches the descriptor, terminates the sandbox when it closes, and fails the run naming the supervisor's exit status and a bounded tail of its stderr: ```text wait failed: Bubblewrap: the sandbox lost its network provider while the workload was running; the proxy network supervisor exited with exit status: 137 (stderr: sent tapfd=7 for tap0 received tapfd=7 Killed) ``` The monitor is disarmed *before* teardown stops the supervisor, so an ordinary shutdown — which closes the same descriptor — is never reported as a loss. Only an exit is detected; see [Limitations](#limitations). ### Example: proxy on v0.9 ```json { "version": "0.9.0-alpha", "containment": "bubblewrap", "process": { "commandLine": "curl -fsSL https://example.com" }, "network": { "egress": { "default": "deny" }, "ingress": { "default": "deny", "hostLoopback": "deny" } }, "runtimeConfig": { "networkProxy": "http://127.0.0.1:8080" } } ``` A proxy request is the proxy-only posture, so `egress.default` must be `deny` with no `allow` / `deny` rules; the chain opens the proxy endpoint alone. Contract versions before `0.9.0-alpha` are retired. Legacy `network.proxy` and host-list configurations cannot be expressed by declaring v0.9; use `runtimeConfig.networkProxy` with a ruleless, deny-default directional egress policy as shown above. The external proxy enforces any host filtering itself. ### Checking host support before you run There is deliberately **no automatic fallback**: a `0.9.0-alpha`+ proxy config that cannot configure private networking fails rather than silently degrading to the weaker shared-host-network model, because a silent degradation would reintroduce exactly the proxy-bypass this mode exists to close. So that callers do not have to discover a missing dependency by failing a run, the host requirements are reported ahead of time. From the command line: ```bash lxc-exec --available-backends ``` This emits the available backends as JSON and exits without running the workload. Bubblewrap advertises a `proxyEnforcement` capability when the host can enforce proxy-only egress, and a `warnings` entry explaining why when it cannot: ```json [ { "backend": "bubblewrap", "capabilities": ["proxyEnforcement"] }, { "backend": "lxc" } ] ``` From the TypeScript SDK, `getPlatformSupport()` surfaces the same fact as `bubblewrapNetwork`; from Rust, `mxc_engine::platform_support()` surfaces it as `bubblewrap_network`. Both are reported **fail closed** — if the probe cannot run, the result is `unsupported`, never "unknown". This check is advisory, not a gate. The runner still probes the dependencies at launch: the probe runs in a different process and at an earlier time, so a package can be removed in between. The pre-flight walk is bounded to a few seconds in total, tighter than the per-tool timeout the launch path allows itself, so `getPlatformSupport()` answers promptly. A host slow enough to exhaust that budget is reported `unsupported` with a warning naming the timeout — the run itself is not subject to that budget, so such a host may still launch successfully. It is also not exhaustive. It confirms `slirp4netns`, the `iptables` tooling and a usable backend, and that the kernel actually grants the unprivileged user and network namespaces `bwrap` will ask for — but a missing `nf_conntrack` module is only detectable once the rules are installed, so that case still surfaces at launch with a targeted error message rather than here. Each call re-walks the dependencies, so removing a package is reflected by the next call and the pre-flight answer never stands in for the runner's own check at launch. This applies to direct Rust and CLI invocations; the TypeScript `getPlatformSupport()` memoizes its result for the lifetime of the SDK module, so a Node caller keeps the first answer it received. ### Caveats - **Host loopback is not sandbox loopback**: inside the private namespace `127.0.0.1` means *the sandbox itself*, not the host. The configured proxy remains reachable at slirp's gateway address `10.0.2.2`; the runner rewrites its loopback endpoint so the sandbox can find it. Other host-local services do **not** come along: slirp itself runs without `--disable-host-loopback`, so the gateway can in principle carry traffic to any host-loopback port, but the egress chain admits only the single `10.0.2.2:` destination and drops the rest. The host-loopback surface is therefore the proxy endpoint alone. - **The supervisor's user namespace is visible to the sandbox**: in proxy mode `bwrap` joins the supervisor's user namespace via `--userns` rather than creating its own, and the namespace descriptor stays open in the workload — `bwrap` keeps it across its own `fork`/`exec` and offers no flag to close it. Re-entering the namespace with `setns` requires `CAP_SYS_ADMIN`, which the sandbox cannot hold: `bwrap` empties the capability bounding set before `exec`, so the workload runs with `CapBnd`/`CapEff`/`CapPrm` all zero. The end-to-end test suite asserts those are zero, because that assumption is what makes the exposed descriptor inert. - **Cooperative routing, enforced egress (v0.9+)**: the runner injects `HTTP_PROXY` / `HTTPS_PROXY` so cooperating clients route through the proxy, and additionally programs a default-DROP egress chain inside the sandbox's private network namespace. Clients that ignore the env vars (raw sockets, custom HTTP clients) can no longer reach the network directly: only loopback and the proxy endpoint are permitted. DNS is deliberately **not** opened — the proxy resolves on the workload's behalf. IPv6 egress is denied outright. An endpoint on `127.0.0.1` or `localhost` is rewritten to the gateway. Although the parser also recognizes `[::1]` as loopback, Bubblewrap **rejects it before launch**: a proxy bound only to IPv6 loopback cannot accept the gateway's IPv4 connection. Hostnames other than `localhost`, additional `127.0.0.0/8` addresses, and wildcard addresses are not valid `runtimeConfig.networkProxy` endpoints in an exact v0.9 request. - **Proxy-only, not direct filtering**: `runtimeConfig.networkProxy` requires `egress.default: "deny"` and no `egress.allow` or `egress.deny` rules. The parser rejects combinations that would discard direct rules or permit bypassing the proxy. - **External proxy delegates host filtering**: MXC does not send hostname lists to the proxy. Configure any destination allow/deny policy in the external proxy itself; its own availability and behavior are the caller's responsibility. - **HTTPS via CONNECT**: HTTP clients use `CONNECT` tunnels for TLS, so certificate validation continues to work end-to-end (the proxy does not see plaintext). ### Choosing address or hostname restrictions `network.egress.allow` and `network.egress.deny` filter IP addresses or CIDR blocks, not DNS names. Do not put a hostname in a `cidr` field: Bubblewrap cannot enforce an IP rule against the workload's changing DNS answers and rejects the request. If policy must inspect requested hostnames, use `runtimeConfig.networkProxy` with a separately configured external proxy. Contract `0.9.0-alpha` provides no MXC-managed host-list policy for that proxy. ## Comparison with LXC | Aspect | LXC | Bubblewrap | |--------|-----|------------| | Privileges | Root required | Unprivileged (user namespaces) | | Rootfs | Downloads distro rootfs | Bind-mounts host filesystem | | Startup | Create → Start → Attach | Single `bwrap` exec; proxy-only and firewall-enforced modes add a user/network-namespace supervisor, `slirp4netns`, and namespace-local firewall chains | | Network isolation | iptables + veth | `--unshare-net` for ruleless deny; private netns + slirp4netns and namespace-local iptables for proxy or firewall-enforced policies | | Dependencies | `lxc-*` tools, templates | `bwrap`; proxy and firewall-enforced modes also need `slirp4netns`, util-linux `unshare` and `nsenter`, iproute2 `ip`, a POSIX `sh` and `sleep`, plus `iptables`, `ip6tables` and their `-restore` counterparts | | Lifecycle | Create/destroy containers | Process dies on exit; proxy mode's supervisor is reaped with it | **When to use Bubblewrap:** - Quick sandboxing without root access - Environments where LXC is not available - Fast iteration (no container create/destroy overhead) **When to use LXC:** - Need a separate rootfs (different distro/packages) - Need container networking with veth interfaces - Need persistent containers across executions ## Running Tests ```bash # Single basic test tests/scripts/run_bwrap_basic_test.sh # Controlling-terminal isolation (requires Python 3) bash tests/scripts/run_bwrap_terminal_isolation_test.sh # All Bubblewrap tests tests/scripts/run_bwrap_all_tests.sh ``` Test configs are in `tests/configs/bubblewrap_*.json`. The terminal test creates private PTY fixtures and checks CLI execution with terminal stdin and redirected streams. Its host positive controls must have a controlling terminal, while each sandbox must have none. It does not inject shell commands or change the host's TIOCSTI settings. The `streaming_bubblewrap` Rust integration suite covers SDK pipes under a controlling terminal and verifies that SDK PTY execution retains its private controlling terminal, input/output, and resize behavior. The streaming suite also runs the real Bubblewrap binary through an isolated wrapper that removes `--die-with-parent`, then checks explicit kill, timeout, and handle-drop cleanup. This reproduces the absence of parent-death protection during startup without relying on a scheduling race. ## Troubleshooting These failures carry the `backend_error` code and exit `-1`. | Message | Meaning | |---|---| | `Bubblewrap (bwrap) is not installed or not on PATH` / version too old | The host has no usable Bubblewrap; install `bubblewrap` 0.5+ | | `requires 'slirp4netns' on PATH` / `requires unprivileged user and network namespaces` | The host cannot provide the sandbox network | | `script_code is empty` / `must not carry credentials` / an egress or proxy refusal | The request is at fault; change it and retry | | `failed to spawn bwrap` / `failed to allocate PTY` / proxy namespace start failure | The request was accepted but the launch faulted | | `could not resolve the host's /bin` (or another system directory) | A merged-/usr symlink such as `/bin -> usr/bin` could not be followed; check that the link and its target are readable | | `readwritePaths entry '…' could not be resolved` (or `readonlyPaths`, `deniedPaths`) | The path goes through a dangling symlink, a symlink loop, or a directory the caller cannot search; fix the path or remove the entry | | `failed to wrap stdio pipes` | The sandbox started and then faulted | ## Limitations - **Linux only** — Bubblewrap requires Linux kernel namespaces - **Deny-by-default filesystem** — the sandbox sees a minimal allowlist of host paths (system binaries, libs, `/etc`, resolver configuration) and nothing else. `$HOME`, `/opt`, `/var`, `/sys`, `/run/user/`, and `/usr/local` are invisible unless explicitly listed in `readonlyPaths` / `readwritePaths`. There is no separate rootfs — the visible paths are bind-mounted from the host, except for the resolver-file copy. Explicitly granting a host directory containing Unix sockets can expose host services outside IP egress filtering. - **Network filtering** — `network.egress` allows or denies numeric addresses and CIDRs without root (rules live in the sandbox's own namespace). Allowed IPv6 destinations remain unreachable until slirp supports IPv6 here. `runtimeConfig.networkProxy` restricts direct egress to the configured loopback proxy endpoint; hostname policy belongs to that external proxy. - **No container lifecycle operations**: Bubblewrap's `ScriptRunner` supports create-and-run execution, not `StatefulSandboxBackend` lifecycle calls. - **Provider-loss detection is exit-based** — in the private-namespace modes a `slirp4netns` that exits mid-run fails the run; one that is alive but wedged is not detected, and reaches the workload as an unreachable network