Skip to content

feat(sandbox): add Bubblewrap sandbox backend for unprivileged Linux execution - #1080

Closed
ramashishmaurya wants to merge 1 commit into
SynapseKit:mainfrom
ramashishmaurya:feat/bubblewrap-sandbox-backend
Closed

ramashishmaurya wants to merge 1 commit into
SynapseKit:mainfrom
ramashishmaurya:feat/bubblewrap-sandbox-backend

Conversation

@ramashishmaurya

Copy link
Copy Markdown
Contributor

Summary

Adds BubblewrapBackend (registered as bubblewrap, aliased bwrap) to provide a daemonless, rootless, and containerless sandbox backend for Linux. It leverages Linux kernel user, mount, and network namespaces (unshare) directly without requiring root permissions, sudo, or container daemons like Docker or Podman.

Type of change

  • Bug fix
  • New feature
  • Documentation update
  • Refactor / internal improvement
  • Dependency / tooling update

Changes

  • New Backend (src/synapsekit/sandbox/backends/bwrap.py):
    • Implements BubblewrapBackend(SandboxBackend) for unprivileged Linux execution.
    • Enforces strict hardening defaults:
      • Host root mounted as read-only (--ro-bind / /).
      • Private virtual filesystems (--dev /dev, --proc /proc).
      • Private writable scratchpad (--tmpfs /tmp).
      • Work tree mounted to /workspace (--dir /workspace, --bind {work_root} /workspace) with working directory set to /workspace.
      • Full namespace isolation (--unshare-user, --unshare-pid, --unshare-ipc, --unshare-uts).
      • Network policy gating: --unshare-net applied under NetworkPolicy.NONE, omitted under NetworkPolicy.EGRESS_ONLY for outbound access.
      • Host environment leakage prevented (--clearenv, sanitized PATH, HOME, TMPDIR, and custom env variables).
      • Lifecycle isolation with --die-with-parent and --new-session.
    • Fails closed on non-Linux platforms or when the bwrap executable is missing.
  • Backend Factory (src/synapsekit/sandbox/backends/base.py):
    • Registered bubblewrap and bwrap in build_backend().
    • Exported in src/synapsekit/sandbox/backends/__init__.py.
  • Unit Tests (tests/sandbox/test_backends.py):
    • Added 7 comprehensive test cases covering build_backend resolution, platform probe gating, binary missing error reporting, available probe capabilities, restrictive start/exec flag verification, and egress policy behavior.
    • Follows house testing standards (no MagicMock/AsyncMock, using hand-written fakes and monkeypatch).
  • Documentation:
    • Updated docs/pc-sandbox.md describing the new backend.
    • Updated CHANGELOG.md under [Unreleased] -> Added.

Testing

  • All existing tests pass (uv run pytest tests/sandbox/ -q) — 48/48 passed
  • New tests added for new behaviour
  • No API keys or secrets in the code
  • Linting and formatting pass (ruff check & ruff format --check)
  • Static type checking clean (mypy src/synapsekit/sandbox)

Notes for reviewer

  • Ideal for running sandboxed agents in locked-down CI/CD runners, serverless environments, or cloud Linux instances where mounting the Docker socket or configuring rootless Podman subuid/subgid maps is prohibited.
  • bwrap execution is ephemeral and dies cleanly with the parent process (--die-with-parent), so no orphaned containers or cleanup background jobs are required.

…execution

Add BubblewrapBackend ('bubblewrap', aliased 'bwrap') for rootless, daemonless sandboxed execution on Linux using kernel user, mount, and network namespaces directly.
AmitoVrito added a commit that referenced this pull request Oct 17, 2026
feat(sandbox): Bubblewrap backend, hardened (supersedes #1080)
@AmitoVrito

Copy link
Copy Markdown
Collaborator

Merged into main via #1084 🎉 Thank you @ramashishmaurya — this is a genuinely useful backend (daemonless, rootless, no container runtime).

I rebased it onto current main and applied a pre-merge security review (all co-authored to you). Three isolation gaps versus the Docker/Podman backends were fixed before merge:

  • Host root exposure: --ro-bind / / let sandboxed code read ~/.ssh, ~/.aws, ~/.env etc. at their real paths, bypassing the overlay + SandboxConfig.exclude. Now binds only a minimal read-only system rootfs (/usr, /bin, /sbin, /lib, /lib64, /etc) plus /workspace.
  • egress_only: omitting --unshare-net shared the host netns (host loopback + cloud metadata endpoint). bwrap has no NAT, so it now always isolates the network and fails closed on egress_only, pointing to podman/docker for outbound.
  • Resource limits: memory/cpus/pids_limit were silently ignored; it now reports enforces_resource_limits=False.

Full rationale in #1084. Appreciate the contribution!

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