feat(sandbox): wire selective network allowlist into BashTool (#10)#144
Merged
Conversation
BashTool now routes commands through spawnNetworkSandbox when network.allowedDomains is a non-empty allowlist on Linux. If the slirp sandbox can't be set up (e.g. the DNS proxy can't bind 127.0.0.1:53), it FAILS CLOSED — re-runs under deny-all-net with a clear note — rather than running unrestricted. Background commands always fail closed (the slirp helper can't safely outlive the turn). - netns.ts: add pure helpers needsNetworkSandbox() (linux + enabled + non-empty allowlist) and denyAllNetwork() (fail-closed config). - bash.ts: foreground net path (capture/timeout/abort via the handle), fail-closed fallback, background deny-all; shared summarize() helper. - Tests: netns.test.ts (decision + config helpers, runs everywhere) + bash.test.ts wiring tests using an injected fake spawner (net path, fail-closed fallback, background) — no real bwrap needed. - docs/security-model.md: document the Linux allowlist, its DNS-name threat model, the :53 requirement, and the fail-closed behavior. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.
Completes #10 by making the selective per-domain network allowlist (mechanism landed in #143) actually used by the Bash tool.
What
BashToolnow routes a command throughspawnNetworkSandboxwhensandbox.network.allowedDomainsis a non-empty allowlist on Linux. Otherwise the existingwrapBashCommandpath is used (deny-all-net via--unshare-netfor[], full network forundefined, macOS sandbox-exec, etc.).Fail closed: if the slirp sandbox can't be set up — most commonly because the allowlisting DNS proxy can't bind
127.0.0.1:53(privileged port) — BashTool re-runs the command under deny-all-net with a clear note, rather than running it unrestricted. Background commands always fail closed (the slirp helper can't safely outlive the turn).Changes
netns.ts— pure helpersneedsNetworkSandbox()anddenyAllNetwork().bash.ts— foreground net path (capture / timeout / abort driven by the handle), the fail-closed fallback, background deny-all; a sharedsummarize()helper for consistent output.netns.test.ts(decision + config helpers, runs everywhere) andbash.test.tswiring tests via an injected fake spawner (happy path, fail-closed fallback, background) — no real bwrap required. The real end-to-end path stays covered bynetns-integration.test.tson the Linux CI job.docs/security-model.md— documents the Linux allowlist, its DNS-name threat model, the:53requirement, and the fail-closed behavior.Limits (documented)
DNS-name allowlisting — a raw-IP dial bypasses it (adequate for git/npm/pip-over-https). Per-domain allowlisting is Linux-only (macOS SBPL has no usable remote-host predicate). Where
:53isn't bindable, it fails closed to deny-all-net.🤖 Generated with Claude Code