Repository navigation
feat(sandbox): Bubblewrap backend, hardened (supersedes #1080) - #1084
Merged
Merged
Conversation
…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]>
7 of 10 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Integration branch for #1080 (Bubblewrap sandbox backend by @ramashishmaurya), rebased onto current
mainwith 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
--ro-bind / /mounted the real host filesystem read-only inside the sandbox, so agent code could read~/.ssh,~/.aws,~/.envetc. at their real paths — bypassing the overlay copy andSandboxConfig.excludethat are the whole point of the sandbox. Now binds only a minimal read-only system rootfs (/usr,/bin,/sbin,/lib,/lib64,/etc) plus the/workspaceoverlay; never the host root or home.egress_onlythe 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 thenonepolicy, and fails closed onegress_only(pointing callers to podman/docker).memory/cpus/pids_limitwere silently ignored (bwrap has no cgroup controls). Added an additiveenforces_resource_limitscapability flag (defaultTrue, others unchanged), setFalsefor bwrap, and documented the gap.Cleanups
except Exception: passaround trusted env JSON parsing.docs/pc-sandbox.mdand 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//runnever bound; network always isolated;egress_onlyfails closed;enforces_resource_limitsFalse). ruff + mypy clean.Closes #1080.