feat(loop): route tool dispatch to a hand sandbox (brain↔hand isolation)#1
Merged
Conversation
Add Config.ToolSandboxID: when set, tool calls dispatch to that sandbox (the "hand") while the run's own SandboxID (the "brain") stays compute-only. This is the loop-side half of brain-hand-spawn (leg 4) — the brain reasons; a separate hand sandbox, created under the user's policy, executes untrusted tool code. loop.go:441 is topos's only tool-execution site (delegated sub-runs re-enter the same loop), so one seam covers all dispatch. Empty ToolSandboxID preserves today's behaviour exactly. Tests: a capturing tool records the sandbox id it ran in — with ToolSandboxID set it sees the hand, not the brain (fails without the routing); the default (unset) still runs in the run's own sandbox. loop pkg coverage 99.2%.
changkun
added a commit
that referenced
this pull request
Jul 6, 2026
…eleton) The walking-skeleton leaf for interactive-session-modes mode 2 (the laptop as a sandbox the control plane drives): let a sandbox.Provider be served over any byte stream, with the ratified trust protections built in. - sandbox/rpc: Serve(conn, provider) + NewClient(conn) sandbox.Provider, a JSON-framed codec for the unary methods (Create/Destroy/Exec/ReadFile/ WriteFile/ListFiles/HealthCheck). Typed errors (ErrNotFound/ErrConflict/ ErrConfined/*APIError) round-trip so callers errors.Is them across the wire. StreamExec is a named follow-on (client returns ErrStreamUnsupported). - sandbox.Confine(provider, root): path-root confinement + the non-overridable secret deny-list (mode-2 trust protections #1/#2), refusing escapes/secrets with ErrConfined before the inner provider. Exercised over an in-memory net.Pipe (no network): full round-trip against sandbox/local, typed-error round-trips, and confined-refused-server-side. sandbox 100% / rpc 95.4%; topos gate green (total 90.4%). Transport wiring onto the tunnel, per-call exec consent, and StreamExec are follow-on leaves.
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.
What
Adds
loop.Config.ToolSandboxID. When set, the agentic loop dispatches tool calls to that sandbox (the hand) while the run's ownSandboxID(the brain) stays compute-only. This is the loop-side half of brain-hand-spawn (leg 4): the brain reasons; a separate hand sandbox — created under the user's policy by the control plane — executes untrusted tool code, so tool code never shares the brain's pod/credentials.Why this is the whole seam
runtime/loop/loop.go:441is topos's only tool-execution site (verified:grep '.Invoke('across the tree returns just this line; delegated/mesh sub-runs re-enter the same loop). So this one change routes all tool dispatch, including delegated sub-runs — the isolation is complete, not partial.Empty
ToolSandboxIDpreserves today's behaviour byte-for-byte (tools run inSandboxID).Tests
TestLoopDispatchesToolsToHandSandbox: a capturing tool records the sandbox id it ran in; withToolSandboxIDset it sees the hand, not the brain. Verified to fail without the routing (runs in the brain), pass with it.TestLoopWithoutHandRunsToolsInRunSandbox: default (unset) still runs tools in the run's own sandbox.runtime/looppackage coverage 99.2%;-raceclean;golangci-lint0 issues.Closes
Satisfies brain-hand-spawn AC-2 ("a tool call dispatched by the loop runs in the hand sandbox, not the brain sandbox") at the SDK level. The control-plane consumer (
latere.ai/x/agents,HandBroker+POST /v1/sessions/{id}/hands) wires the hand id into the loop config once a topos release carrying this field is cut.Note
make all'scover-checkreports total 89.7% < 90%, but this is pre-existing onmain(identical total with and without this change) — the recently-addedexamples/graph+examples/delegationpackages sit at 0% and drag the total. This PR's own package is 99.2%; fixing example coverage (or excluding./examples/...from the coverage scope) is a separate concern.