Skip to content

TD-5306: a sandboxed command reaches boundary.network's hosts, and nothing else - #132

Open
captcrock wants to merge 1 commit into
mainfrom
td/5306-sandbox-network-bridge
Open

captcrock wants to merge 1 commit into
mainfrom
td/5306-sandbox-network-bridge

Conversation

@captcrock

Copy link
Copy Markdown
Contributor

PR 2 of 2 for sandboxing.md R3. The approach was signed off ahead of time, on two conditions: it sits behind a setting, and the network stays fully off by default. It builds on TD-5305's proxy, already merged.

Setting: sandbox.network: deny | allowlist, at the user level and per workspace.

  • deny is the default.
  • A workspace's own value wins.
  • A repo-shipped allowlist is a trust loosening, so it waits for the trust card.

How it works (Linux, bubblewrap) — design option 1, with the seccomp filter unchanged:

  • Bridge: the sandbox's first process is a stdlib bridge (egress.BRIDGE_SOURCE, run with python -I -S -c). It binds 127.0.0.1:3128 inside the command's own network namespace, forks a relay, and execs /bin/sh -c <command>.
  • Relay: for each connection it asks the daemon, over a socket pair handed in before the start, for a connected socket (SCM_RIGHTS). The daemon serves that socket with EgressProxy (TD-5305).
  • Host side: nothing listens on the host, and socket(AF_UNIX) is still refused inside.
  • Token: the token travels in the host shell's environment as HTTP(S)_PROXY/ALL_PROXY, never on a command line.
  • Grant lifetime: the daemon drops its copy of the command's end once the command starts. When the last process in the sandbox exits, the serve loop ends and the token is revoked. This covers foreground runs, background jobs, and a timed-out command turned into a job.
  • Audit: allows and denies go to the daemon's audit writer (network_egress).
  • Result line: it now says "network only to the hosts on boundary.network through the sandbox proxy".

Tests (test_sandbox_network.py, real bubblewrap; CI requires it via TST_REQUIRE_SANDBOX=1). No outside host is contacted: the allowed host is a local server reached through the proxy's connect seam.

  • A listed host is reached, and the allow is audited with the tool call id and session.
  • An unlisted host answers 403 with the boundary.network reason.
  • The owner's condition: with every proxy variable removed, a command cannot connect to the allowed address, the host's loopback port, or 1.1.1.1. All three have no route.
  • The grant ends with the command.
  • deny, or no hosts listed, sets no proxy and grants nothing.
  • Unit tests cover the plan argv, the setting merge, and the trust loosening.

Limits (documented):

  • SSH and tools that ignore proxy variables cannot connect.
  • The packaged app runs the bridge on the system python3; without it the network stays off.
  • macOS (R2) and a Windows backend (R6) are not here: CI is Linux-only and cannot test them.

Suite: full core suite 9087 passed. The one failure, the outbound-hosts confinement test, is fixed in this PR by listing sandbox/egress.py with its reason. ruff and mypy are clean. Release scan: 0 hits.

🤖 Generated with Claude Code

…thing else

Second R3 PR. sandbox.network: deny | allowlist (deny by default, at
user and workspace level; a workspace allowlist waits for trust). With
allowlist, a sandboxed command's first process is a stdlib bridge that
listens on 127.0.0.1:3128 inside the command's own network namespace,
forks a relay and execs the command. The relay gets one connected
socket per connection from the daemon over a socket pair handed in
before the start (SCM_RIGHTS), and the daemon serves it with the
TD-5305 proxy. The seccomp filter is unchanged and nothing on the host
listens. The grant ends when the last process in the sandbox does.

Real bubblewrap tests: a listed host is reached and audited with its
tool call; an unlisted one is 403; with the proxy variables removed a
command has no route out at all (the owner's condition); deny, or no
hosts, sets no proxy and grants nothing.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.

1 participant