Skip to content

feat(sandbox): Bubblewrap backend, hardened (supersedes #1080) - #1084

Merged
AmitoVrito merged 6 commits into
mainfrom
feat/bwrap-sandbox-hardened
Oct 17, 2026
Merged

AmitoVrito merged 6 commits into
mainfrom
feat/bwrap-sandbox-hardened

Conversation

@AmitoVrito

Copy link
Copy Markdown
Collaborator

Integration branch for #1080 (Bubblewrap sandbox backend by @ramashishmaurya), rebased onto current main with a pre-merge security review applied.

The original backend is a great idea — a daemonless, rootless Linux sandbox needing neither Docker/Podman nor root. But as submitted it weakened isolation versus the existing Docker/Podman backends. This branch keeps the feature and fixes three isolation gaps (plus cleanups), each as an atomic commit co-authored with @ramashishmaurya.

Security fixes

  • Host root exposure (critical). --ro-bind / / mounted the real host filesystem read-only inside the sandbox, so agent code could read ~/.ssh, ~/.aws, ~/.env etc. at their real paths — bypassing the overlay copy and SandboxConfig.exclude that are the whole point of the sandbox. Now binds only a minimal read-only system rootfs (/usr, /bin, /sbin, /lib, /lib64, /etc) plus the /workspace overlay; never the host root or home.
  • Fake egress-only (high). Under egress_only the backend omitted --unshare-net, running in the host network namespace — reaching host loopback services and the cloud metadata endpoint (169.254.169.254), far more than "egress only". bwrap has no NAT, so it now always --unshare-net, advertises only the none policy, and fails closed on egress_only (pointing callers to podman/docker).
  • Silent resource caps (medium). memory/cpus/pids_limit were silently ignored (bwrap has no cgroup controls). Added an additive enforces_resource_limits capability flag (default True, others unchanged), set False for bwrap, and documented the gap.

Cleanups

  • Removed a bare except Exception: pass around trusted env JSON parsing.
  • Corrected docs/pc-sandbox.md and the CHANGELOG to describe the hardened behavior.

Tests

49/49 sandbox tests pass; the tests that previously enshrined the insecure flags now assert the secure contract (host root / /home / /root / /run never bound; network always isolated; egress_only fails closed; enforces_resource_limits False). ruff + mypy clean.

Closes #1080.

ramashishmaurya and others added 6 commits October 17, 2026 19:56
…execution

Add BubblewrapBackend ('bubblewrap', aliased 'bwrap') for rootless, daemonless sandboxed execution on Linux using kernel user, mount, and network namespaces directly.
The Bubblewrap backend mounted the real host root read-only
(`--ro-bind / /`), which let sandboxed code read ~/.ssh, ~/.aws, ~/.env
and every other host secret at its real path -- bypassing the overlay
copy and SandboxConfig.exclude that are the entire point of the sandbox.
Bind only a minimal read-only system rootfs (/usr, /bin, /sbin, /lib,
/lib64, /etc via --ro-bind-try) plus the isolated /workspace overlay;
never bind the host root or home directories.

Co-authored-by: Ashish Maurya <[email protected]>
Under the egress_only policy the backend omitted --unshare-net, so the
sandbox ran in the host network namespace -- reaching host loopback
services (unauthenticated local DBs/admin UIs) and the cloud metadata
endpoint (169.254.169.254), i.e. far more than "egress only". bwrap has
no NAT and cannot provide true egress-only networking on its own.

Always pass --unshare-net, advertise only the 'none' network policy in
probe(), and fail closed in start() when egress_only is requested,
pointing callers to the podman/docker backends for outbound access.

Co-authored-by: Ashish Maurya <[email protected]>
config.memory, config.cpus and config.pids_limit were silently ignored
by the bwrap backend (it has no cgroup controls), while pids_limit was
stashed in the handle metadata as if it were applied -- so a fork bomb or
memory hog in the sandbox could take down the host with no indication the
caps were a no-op. Add an additive `enforces_resource_limits` capability
flag (default True, so other backends are unchanged), set it False for
bwrap, drop the misleading metadata, and document the limitation.

Co-authored-by: Ashish Maurya <[email protected]>
The environment dict is serialized by start() via json.dumps, so a
json.loads failure in _build_command is a real bug, not something to
silently drop with `except Exception: pass`. Let it surface.

Co-authored-by: Ashish Maurya <[email protected]>
Update the pc-sandbox backend notes and the CHANGELOG entry to describe
the hardened bwrap behavior: minimal read-only rootfs (no host root/home),
always-isolated network with egress_only rejected, and no resource-limit
enforcement (enforces_resource_limits=False).

Co-authored-by: Ashish Maurya <[email protected]>
@AmitoVrito
AmitoVrito merged commit bfaaa6a into main Oct 17, 2026
28 checks passed
@AmitoVrito
AmitoVrito deleted the feat/bwrap-sandbox-hardened branch October 17, 2026 18:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants