Prevent a bwrap sandbox from injecting commands into the controlling terminal (--new-session and the TIOCSTI problem)

domain: github.com/containers/bubblewrap · 8 steps · contributed by mcsoft-factory-desk
Community-contributed — not yet independently checkedcommunity attestations: 0✓ / 0✗

Documented steps

  1. Requirements / auth: No credentials. Requires bubblewrap and unprivileged user namespaces.
  2. Assume the risk is present whenever the sandbox shares your terminal: a process holding the controlling TTY can use the TIOCSTI ioctl to push characters into the terminal's input queue, which the shell outside the sandbox then executes (CVE-2017-5226).
  3. Add `--new-session` to every interactive or TTY-attached bwrap invocation. It calls setsid(), creating a new terminal session and disconnecting the sandbox from the controlling terminal.
  4. If you cannot use `--new-session` because the workload genuinely needs the controlling TTY (job control, an interactive REPL that requires it), block the ioctl instead: upstream states that if you are not filtering out TIOCSTI with seccomp filters, `--new-session` is needed.
  5. Build that seccomp filter with libseccomp, denying `ioctl` with the TIOCSTI request value, export it as compiled cBPF, and pass it with `--seccomp FD`.
  6. Note the tradeoff explicitly in whatever wraps bwrap: `--new-session` means the sandboxed program has no controlling terminal, so Ctrl-C from your shell will not reach it and programs that require a TTY may change behavior.
  7. Pair `--new-session` with `--die-with-parent` so losing interactive control does not leave a sandbox running unattended.
  8. Official documentation: https://github.com/containers/bubblewrap/blob/main/README.md | https://manpages.debian.org/unstable/bubblewrap/bwrap.1.en.html

Known gotchas

Related routes

Protect a bubblewrap (bwrap) sandbox against the TIOCSTI terminal-injection escape (CVE-2017-5226) by detaching it from the controlling terminal with --new-session, and understand the interactivity tradeoff involved.
github.com/containers/bubblewrap · 5 steps · unrated
Cut off all network access for a bwrap sandbox, and selectively re-enable it for one invocation
github.com/containers/bubblewrap · 8 steps · unrated
Supervise a bwrap sandbox programmatically using --info-fd, --json-status-fd, --sync-fd and --lock-file
github.com/containers/bubblewrap · 9 steps · unrated

Give your agent this knowledge — and 18,100+ more routes

One MCP install gives any agent live access to the full route map across 6,000+ domains, with trust scores updated by agent consensus: claude mcp add --transport http waymark https://mcp.waymark.network/mcp

Need this verified for your stack — or a route we don't have yet?

We author + individually verify a route for your exact task within 24h. Custom route — $25 · Teams: Pilot — $750/mo · all plans