Brian Hung
Projects
ai-sdk-harness
Sandboxes and durable runtimes for running Claude Code and Codex through the AI SDK.
Moving a working tree between sandboxes
createSession()
spawn: tar czf -
writeBinaryFile, then tar xzf
LocalSandboxProvider
child_process and fs
DockerSandboxProvider
docker exec in a container
CloudflareSandboxProvider
Sandbox Bridge HTTP API
Session in sandbox A
at a turn boundary
Session in sandbox B
fresh, from any provider
checkpointSandbox
streams out, stages nothing
CheckpointStore
memory or R2, by key
restoreSandbox
overlays the tree
The file tree moves; running processes don't. Files made since the checkpoint stay in place.
Running a turn on any engine
session.call: the state as JSON
ready_for_next_step: run the next slice
runHarnessSession
pure orchestration, JSON only
Cloudflare Workflows
workflowDurableSession
Temporal
temporalDurableSession
In-process
localDurableSession
harness:slice
up to 750 s of the turn
SessionLog
chunks, per slice
agent in its sandbox
Claude Code or Codex
Each slice is a checkpoint, so a restart resumes from the last one.
The sandbox keeps running between slices, and the next slice reattaches to it.
One Durable Object per session
prompts, answers
events, permission requests
single-threaded: no locks
every frame, with its seq
Clients
phone, laptop, chat threads
Runner
exactly one, fenced by generation
AgentSessionDO
appendAndFanout: the log assigns the next seq
durableObjectSessionLog, on the DO's SQLite
Connected clients
each frame, live
Replay
from a lastSeq cursor
SSE readers
Last-Event-ID cursor
Export and fork
?until=N, ?seal=1
Text streams out live, chunk by chunk, and is stored once, as one message.
Serving local tools to a remote session
Outcomes
every call ends in exactly one
host-tool-call
host-tool-result
tool-call
tool-result
Runner
may live in a cloud sandbox
AgentSessionDO
one host lease, per-call budgets
connectToolHost
relay-host, on your machine
completed
the result, capped at byteBudget
unavailable
no host attached: safe to retry
timeout
deadlineAt passed: call cancelled
ambiguous
host left mid-call: never retried
A repeated call replays its recorded result, so the host never runs it twice.