Repository navigation
Description
Context
The Bubblewrap sandbox backend (BubblewrapBackend, merged in #1084) currently supports only the none network policy — fully isolated via --unshare-net. During the pre-merge security review we deliberately made egress_only fail closed rather than ship the original behavior.
The original PR implemented egress_only by simply omitting --unshare-net, which left the sandbox in the host network namespace. That is not egress-only: it exposes host loopback services (unauthenticated local DBs/admin UIs) and the cloud metadata endpoint (169.254.169.254, i.e. IAM credential theft) — strictly more access than outbound-only. bwrap has no NAT of its own, so it cannot provide true egress-only networking unassisted.
Today, callers needing outbound access from a sandbox must use the podman or docker backend (which use a NAT bridge). This issue tracks giving bwrap real egress-only support.
Proposal
Implement egress_only for BubblewrapBackend via slirp4netns, the standard userspace network helper for rootless containers:
- Keep
--unshare-net(the sandbox always gets its own network namespace — no host loopback/metadata access). - Launch
slirp4netnsagainst the sandboxed process's network namespace to provide a NAT'd tap device with outbound-only connectivity. - The usual wiring: run bwrap with
--unshare-net+--info-fdto read the child PID, startslirp4netns --configure --mtu=65520 <pid> tap0, and use a sync fd (--block-fd/--userns-block-fd) so the child waits until the tap is ready before exec. - Advertise
egress_onlyinprobe().network_policiesonly when theslirp4netnsbinary is present; otherwise continue to fail closed.
Acceptance criteria
probe()listsegress_onlyiffslirp4netnsis available on the host.- With
egress_only: outbound TCP/DNS works, but host loopback (127.0.0.1) and the link-local metadata endpoint (169.254.169.254) are unreachable from inside the sandbox. - With
none: unchanged (fully isolated). - If
slirp4netnsis unavailable andegress_onlyis requested,start()fails closed with a clear message (current behavior). - Failure of the slirp setup must fail safe (no connectivity), never fall back to sharing the host namespace.
Notes / risks
- The multi-process fd-sync dance does not fit the current one-shot
run_process(full_command)helper insandbox/backends/base.py— it needs a sidecar process kept alive for the command's duration plus teardown. Expect non-trivial plumbing there. - This is genuinely Linux-host + real-binary territory, so it needs a real integration test gated on
slirp4netns+bwrapbeing installed (wired into CI so it actually runs, not silently skipped), per the house testing standards. Monkeypatched command-construction unit tests are not sufficient on their own here.
References
- Backend:
src/synapsekit/sandbox/backends/bwrap.py - Fail-closed logic added in feat(sandbox): Bubblewrap backend, hardened (supersedes #1080) #1084 (commit
4aab1a3) - Sibling egress implementations:
podman.py/docker.py(--network bridge)
Activity
docs(changelog): link bwrap egress-only follow-up (#1085)