Repository navigation
Description
Epic: SandboxTransport — language-neutral remote sandbox exec over gRPC
Tracks the work in the SandboxTransport spec (Status: Design — approved for planning) and ADR-0024 (Accepted). Landed via #78.
Origin
Today the harness runs every Pi tool call (read/write/bash/grep) inside a sandbox pod via kubectl exec — the harness dials into the pod through the kube API. That only works when the harness can reach the sandbox's API server, which rules out sandboxes behind NAT, on-prem, on a laptop, or in another cloud — and blocks the top driver: bring-your-own (untrusted 3rd-party) sandboxes (spec §1).
Target architecture
Invert connectivity: the sandbox dials out to a broker the harness also talks to, over a language-neutral, firewall-friendly protocol (one outbound TLS connection, HTTP/2 on :443), without changing the Pi loop, session backend, or leaf queue (spec §2–§3).
Sandbox (laptop / on-prem / other cloud / same cluster)
worker (Go static binary) — SandboxWorker.Attach client
│ outbound only, TLS :443, HTTP/2 (WorkerFrame ↑ / ServerFrame ↓)
▼
Kubernetes
relay (Deployment, 1 replica) — parks Attach streams; mirrors presence → Redis pool
│ in-cluster gRPC (SandboxExec.Exec/Abort)
▼
Harness (central brain: Pi loop + LLM) Redis sandbox pool
SandboxTransport.exec(...) ← the ONE seam
├─ [local] KubectlTransport (existing kubectl-exec, renamed)
└─ [remote] GrpcRelayTransport (new; calls the relay)
select-sandbox → leases pod OR remote record → returns a transport
Key decisions (locked) — see ADR-0024
- Brain stays central. The Pi loop + LLM key never leave the harness; an untrusted sandbox only ever receives commands and returns bytes (trust-correct for driver harness: tsc fails on cli.ts gateway-header cast (
x-api-key: null→ Record<string, string>) #1). - Contract is a Protobuf IDL (
sandbox/v1), not a TypeScript interface. Any gRPC-capable language can host a worker; TS is just one generated client (§4). - gRPC-native over HTTP/2 on
:443, not Connect — full-duplex bidi needs HTTP/2 regardless, so Connect adds a second toolchain for no gain on the streaming core (§5). - Single-replica, presence-only relay — no matchmaking, no presence glue beyond mirroring workers into the existing Redis pool;
select-sandboxmatches unchanged (§6). - One Go reference worker — the honest proof the contract is genuinely language-neutral (§7).
- Per-sandbox bearer token at the edge day-one; SPIFFE/mTLS upgrades into the same
Attachseam later (§9).
What does NOT change
The Pi orchestration loop, run-turn, the session backend (RedisSessionBackend), the leaf queue (@sh/work-queue), and the sandbox pool/lease logic. The change slots strictly below the current ExecInPod call sites (spec §3).
Two tracks (build in parallel off the shared contract)
The worker build is separated from the backend and coded by a different contributor; per the repo's lifecycle conventions, implementation plans are local-only (docs/plans/, gitignored) and per-contributor — one for the backend, one for the worker.
- Backend (TypeScript / in-cluster): ST1: sandbox/v1 Protobuf contract — language-neutral wire IDL (shared foundation) #84 (proto), ST2: backend — SandboxTransport seam + KubectlTransport rename (pure refactor) #85 (seam), ST3: backend — relay + GrpcRelayTransport + presence mirror + select-sandbox #86 (relay + transport), + backend half of ST5: integration & live gate — cross-transport conformance + end-to-end leaf (Kind → OCP) #88.
- Worker (Go / sandbox side): ST4: worker — Go reference worker (dial Attach, run/stream/abort, dedup, dual timeout) #87 (Go worker) + worker half of ST5: integration & live gate — cross-transport conformance + end-to-end leaf (Kind → OCP) #88; consumes the ST1
.proto.
Phases (dependency-ordered)
- ST1: sandbox/v1 Protobuf contract — language-neutral wire IDL (shared foundation) #84 — ST1:
sandbox/v1Protobuf contract (shared foundation; build first) - ST2: backend — SandboxTransport seam + KubectlTransport rename (pure refactor) #85 — ST2: backend —
SandboxTransportseam +KubectlTransportrename (pure refactor, ships first) - ST3: backend — relay + GrpcRelayTransport + presence mirror + select-sandbox #86 — ST3: backend — relay +
GrpcRelayTransport+ presence mirror +select-sandbox(behindSH_REMOTE_SANDBOX; depends on ST1: sandbox/v1 Protobuf contract — language-neutral wire IDL (shared foundation) #84, ST2: backend — SandboxTransport seam + KubectlTransport rename (pure refactor) #85) - ST4: worker — Go reference worker (dial Attach, run/stream/abort, dedup, dual timeout) #87 — ST4: worker — Go reference worker (depends on ST1: sandbox/v1 Protobuf contract — language-neutral wire IDL (shared foundation) #84)
- ST5: integration & live gate — cross-transport conformance + end-to-end leaf (Kind → OCP) #88 — ST5: integration & live gate — cross-transport conformance + end-to-end leaf, Kind → OCP (depends on ST3: backend — relay + GrpcRelayTransport + presence mirror + select-sandbox #86, ST4: worker — Go reference worker (dial Attach, run/stream/abort, dedup, dual timeout) #87)
Deferred / follow-up (spec §13.4, ADR-0024) — not scheduled here
- Untrusted-BYO isolation → SPIFFE/SPIRE mTLS per-connection identity on the same
Attachendpoint. - Multi-replica relay / HA (adds a presence map — K8s API or Redis pub/sub).
- Private-mesh reachability (Headscale / WireGuard) for fleets refusing a public endpoint.
- Additional-language workers (e.g. Python) — the proto already permits them.
- HTTP/1.1-only proxy traversal — the Connect / split-stream variant of §5.
Working conventions
- Spec:
docs/specs/2026-07-08-sandbox-transport-grpc-design.md+ registry row (docs/specs/README.md). Decision:docs/adrs/0024-sandbox-transport-remote-exec.md. - Plans live in
docs/plans/(local-only, gitignored), named for the spec, deleted once coded. - DCO:
git commit -s; attribution trailerAssisted-By: Claude (Anthropic AI) <[email protected]>(neverCo-authored-by).
Activity
docs: register SandboxTransport (ST) track in the milestone registry
pdettori commentedon Aug 27, 2026
ST4 (worker) is complete — #87 / PR #172
The Go reference worker is done and green in CI. It replaces the HELLO WORLD stub with
real
bash -cexecution in its own process group,timeout_senforcement, process-groupkill on abort, fingerprint-guarded dedup of redelivered
req_ids, and reconnect thatpreserves the dedup cache. 56 tests under
-race.Epic status this moves: ST1 (proto) → ST3 (relay + transport) → ST4 (worker) done.
ST5 (#88) is now unblocked — the worker actually runs commands, which was the stated
blocker on the live gate. I have posted a handover on #88 covering what ST4's acceptance
battery proves and, more usefully, the two things it deliberately does not prove:
the fake relay is self-authored (so its agreement with the contract is not independent
evidence), and cross-transport equivalence is untested.
Four findings from ST4 that belong to the epic rather than to the worker, all detailed
on #87:
req_idis not unique per worker. The harness seeds its counter at module scope —per process — while
select-sandboxdeliberately shares sandboxes across runs, so tworeplicas both send
1, 2, 3…to one worker. The worker ships a fingerprint guard(now covering command, stdin,
timeout_s, andstreaming) as defense-in-depth, butthe real fix is a globally unique id and it belongs upstream in ST1/ST3.
sandbox/v1—Endhas no datafield, so "a single
Endcarrying full stdout" cannot be built. The worker buffers andemits
ChunkSize-capped frames at exit instead. The spec prose wants correcting.redelivered streaming
cat filereturns exit 0 with empty content. The worker isspec-compliant; the gap is in the contract. Unreachable today because nothing
redelivers a
req_id— which is exactly why it should be settled before something does.Fixed in the PR; worth noting as a class — the "static binary, no runtime deps"
requirement is about the binary, while
bashis a dependency of the commands.Worker-specific follow-ups that are not epic-level are tracked separately in #173.
Assisted-By: Claude Code
docs(notes): move the ST4 write-ups out of the repo and into the issues
pdettori commentedon Aug 27, 2026
ST4 merged — 4 of 5 tracks done, #88 is the only one left
PR #172 merged to
mainat84118c9. #87 closed. Checklist above updated.ST1 → ST2 → ST3 → ST4 shipped. ST5 (#88) is unblocked, and specifically unblocked in the
sense that mattered: the stated blocker was "no leaf can complete through the remote path
until the worker actually runs commands." It does now.
What the epic gained
The worker is no longer a connectivity stub. On
mainit spawnsbash -cper exec in itsown process group, streams stdout and stderr as 32 KiB
Chunkframes on distinct streamenums, enforces
timeout_slocally by killing the group, dedups redeliveredreq_idsbehind a fingerprint over command + stdin +
timeout_s+streaming, reconnects withjittered backoff while preserving its dedup cache, and advertises capabilities probed
from
PATHrather than a hardcoded list. 56 tests,-raceclean,go test -race ./...wired into CI for the module.
Driver #2 — the seam is not secretly TS-shaped — now has its evidence: a non-TypeScript
worker satisfies the contract, built only against
sandbox/v1.What ST5 inherits, stated honestly
Detail is on #88; the two things worth surfacing at epic level:
Attachwith areal
bash, and it is the only way to reach the redelivery path (the production relaycannot redeliver a
req_id) — but it encodes this repo's reading of the contract, so itsagreement is not independent. The gated interop test against the real relay exists and
has never run. That is ST5's cheapest first step.
GrpcRelayTransport. §11's conformance battery against both transports is whatactually discharges driver M5: Compaction-checkpoint fast path + budget voter #2's swappability claim.
Four findings that belong to the epic, not the worker
req_idis not unique per worker.grpc-relay-transport.tsseeds its counter atmodule scope — per process — while
select-sandboxdeliberately shares sandboxes, so twoharness replicas both send
1, 2, 3…to one worker. The worker ships a fingerprint guardas defense-in-depth (widened during review after a probe showed a redelivery with a
larger
timeout_sbeing failed off a stale cache entry in ~650 µs without running), butthe real fix is a globally unique
req_idand it belongs in ST1/ST3. ST5 will hitthis the moment more than one replica shares a sandbox.
sandbox/v1. "A singleEndcarryingfull stdout" cannot be built —
Endhas no data field. The worker buffers and emitsChunkSize-capped frames at exit. The spec prose wants correcting.redelivered streaming
cat filereturns exit 0 with empty content. The worker isspec-compliant; the gap is in the contract. Unreachable today because nothing redelivers
a
req_id— which is why it is worth settling before something does. Note the twotransports will differ here:
KubectlTransporthas no dedup cache, so it re-runs andreturns output. ST5's conformance battery has to pick the correct behavior.
MaxCallRecvMsgSizeis unconfigured, so abase64write payload above the4 MiB default kills the whole stream rather than one exec. Needs a decision on both ends
and a documented max write size.
Worker-specific follow-ups deliberately not fixed: #173, audited against shipped code.
Deferred by design, unchanged
mTLS/SPIFFE (§9) is still the bearer token's successor and slots into the same
Attachendpoint with no wire change; additional-language workers (§13.4) remain out of scope.
Assisted-By: Claude Code
pdettori commentedon Aug 27, 2026
Live gate validated manually; laptop demo filed as #174
I ran the remote path end-to-end in a local kind cluster today. It works, with no
kubectl execanywhere in the path:The proof is an A/B on a file that differs between backends. The in-cluster
sandbox-Npods are Alpine; the worker image is RHEL. Same leaf, same file path:
AlpineFLAGGEDCLEARThe model can only name RHEL 9.8 by having read the worker's own filesystem. Mirror control
(
pattern: "Red Hat"→FLAGGEDon the worker) confirms it from the other direction.Also validated today, below the leaf: the gated interop test against the real TypeScript
relay passes (
SH_LIVE_RELAY=1— it had never been run), and the realGrpcRelayTransportdrives the real relay and real worker with stdout/stderr split, stdinround-trip, and
timeout:1in ~1s.Two traps worth recording at epic level
SH_REMOTE_SANDBOX=1alone does not route to a remote worker.select-sandboxbuilds
candidates = [...pods, ...grpcRecs]and picks least-loaded-first, so idlein-cluster pods win. The remote worker is a pool peer, not a replacement. My first
remote run silently used a pod and looked successful. Anyone demoing or gating on this
must remove local candidates (or use a dedicated pool selector) — and ST5: integration & live gate — cross-transport conformance + end-to-end leaf (Kind → OCP) #88's conformance
work should assert which backend served, not merely that a run succeeded.
deploy/knative/relay-deployment.yamlomitsSH_RELAY_TOKEN. Relay auth isfail-closed, so the manifest as shipped produces a relay that rejects every Attach.
Neither is a code defect; both are documentation/manifest gaps that cost a failed run each.
The cluster has been reverted to its prior state. #174 tracks turning this into a
one-command laptop demo (kind + worker as a plain
docker run, which is the configurationthat actually demonstrates driver #1 — a pod-based worker proves the plumbing but not the
inverted connectivity).
Assisted-By: Claude Code
pdettori commentedon Aug 28, 2026
Epic complete — ST1 through ST5 shipped
ST5 (#88) closed; the checklist above is now fully ticked. The closing work is 12 commits with
make typecheck,make test(605 passed / 13 skipped) andgo test -race ./...green.What has evidence
x-api-key: null→ Record<string, string>) #1 — untrusted BYO sandboxes. The sandbox dials out; there is nokubectl execanywhere in the remote path; the Pi loop and the LLM key never leave the harness. Proven end to end by a leaf whose tool calls demonstrably executed on the remote worker's own filesystem — an A/B on/etc/os-releasethat gives opposite verdicts per backend — on Kind (twice) and on OpenShift.sandbox/v1, and one conformance battery that both per-call transports pass identically, including the output cap and the abort/SIGKILL that enforces it.What this epic does NOT establish
Recorded deliberately, because a closed epic is what future work builds on — and this branch exists precisely because the spec had claimed more than the code delivered.
SandboxTransportenforces the cap" was false when written.persistentExecInPodis a third transport, uncapped, serving the file-reading tools, and absent from the battery. Spec §8, ADR-0024 andtransport.tsnow name the exception. → persistentExecInPod is an uncapped third SandboxTransport, and it serves the file-reading tools #180KubectlTransportapplies no default deadline; the gRPC path always applies 120 s. The battery cannot see it: its timeout case always passes an explicit timeout, so neither default is ever exercised. → KubectlTransport has no default deadline while GrpcRelayTransport always applies 120s, and the battery cannot see it #182createPodBashOpsdiscards stdout, so the cap protects nothing on that path and misreports the kill. → A bash flood is SIGKILLed at the output cap but reported to the model as success #181Attachon:443behind a Route with TLS, plus a NetworkPolicy lockingSandboxExecto in-cluster callers per §9. The gate runs plaintext h2c on the relay ClusterIP, as §13.4 anticipated.Two defects the closing work found and fixed
KubectlTransportmade itpersistentExecInPod's fallback on channel death;readFilediscardedexitCode; Pi's Edit is read-whole-file → write-whole-file. A >8 MiB Edit plus a channel death wrote 8 MiB and the truncation marker into the source — nondeterministically, depending on whether the persistent channel happened to survive.readFilenow refuses to return content it cannot vouch for.req_idwas not unique across replicas (req_id is not globally unique: colliding ids from multiple harness replicas misroute frames at the relay #179, fixed). Worse than the worker-side dedup problem it was first reported as: the relay keys sinks byreq_idper sandbox, so a collision replaced one caller's sink — that exec hung to its deadline while the other received both execs' output interleaved. Silently. The relay now refuses a duplicate in-flightreq_id.Also corrected in the spec: §7 and §8 both promised "a single
Endcarrying full stdout", whichsandbox/v1cannot express —Endhas no data field — and §8 omitted that a dedup cache hit returns an exit code with no output, which differs fromKubectlTransport's re-run.Remaining follow-ups
#173 (worker), #174 (laptop demo), #177 (ghcr paths after the org rename), #178 (
setup-ocp.shexit code), #180, #181, #182. §13.4's deferred items — mTLS/SPIFFE, multi-replica relay HA, private mesh, extra-language workers, HTTP/1.1 traversal — remain unscheduled by design.Assisted-By: Claude Code
fix(k8s-sandbox): enforce the output cap in KubectlTransport too
fix(k8s-sandbox,sandbox-relay): make req_id unique across replicas
test(knative-server): manifest-shape test for both worker Deployments
docs(spec,adr): correct §7/§8 and record the req_id + output-cap deci…
test(deploy/knative): assert a worker disconnect re-leases a healthy …
docs(specs): ST6 — seam-wide output cap + explicit truncation contract