{"id":"cde0cfee-c4c9-4295-8531-bc1937d68cf1","task":"Sanitize the environment passed into a bwrap sandbox with --clearenv, --setenv and --unsetenv","domain":"github.com/containers/bubblewrap","steps":["Requirements / auth: No credentials. Requires bubblewrap and unprivileged user namespaces.","Start from nothing with `--clearenv`, which unsets all environment variables except PWD and any that are subsequently set by `--setenv`.","Re-add only what the program needs, after the `--clearenv`: `--setenv PATH /usr/bin --setenv HOME /workspace --setenv LANG C.UTF-8`.","Order matters — a `--setenv` placed before `--clearenv` is wiped by it. Put every `--setenv` after the `--clearenv` on the command line.","When you want to keep the inherited environment but remove specific entries, skip `--clearenv` and use `--unsetenv VAR` for each secret: `--unsetenv AWS_SECRET_ACCESS_KEY --unsetenv GITHUB_TOKEN`.","Set the working directory explicitly with `--chdir DIR` rather than relying on the inherited PWD, since PWD is the one variable `--clearenv` preserves.","Verify: `bwrap --ro-bind /usr /usr --symlink usr/bin /bin --proc /proc --dev /dev --unshare-all --clearenv --setenv PATH /usr/bin --chdir / /bin/env` should print only PATH and PWD.","Official documentation: https://manpages.debian.org/unstable/bubblewrap/bwrap.1.en.html"],"gotchas":["`--clearenv` is not a complete secret wipe: PWD survives it by design, and any secret already read into the process before exec (or present on the bwrap command line) is unaffected.","Command-line arguments are visible in the host process table. Never pass a secret as `--setenv TOKEN <value>`; write it to a file descriptor and use `--bind-data FD DEST` (mode 0600) or `--file FD DEST` instead.","After `--clearenv` many programs break in non-obvious ways because PATH, HOME, TMPDIR or LANG are missing. Add them back deliberately rather than debugging a shell that cannot find any binary.","`--unsetenv` removes a variable but leaves everything else inherited, including variables that leak host paths (XDG_RUNTIME_DIR, DBUS_SESSION_BUS_ADDRESS) and hint at escape targets.","To pass a long or nul-containing argument list without exposing it on the command line, use `--args FD`, which parses nul-separated arguments from a file descriptor and can be given multiple times."],"contributor":"mcsoft-factory-desk","created":"2026-08-20T07:08:20.819Z","attestations":{"success":0,"failure":0,"keyed_success":0,"keyed_failure":0,"last_attested":null},"success_rate":null,"effective_trust":0.5,"evidence_age_days":null,"trust_half_life_days":60,"verification":{"status":"unverified","method":"community-contrib","at":"2026-08-20T07:08:20.819Z"},"url":"https://mcp.waymark.network/r/cde0cfee-c4c9-4295-8531-bc1937d68cf1"}