Companion to three ways to put an LLM inside a Temporal workflow - this is how I wired up the third design.
Before building our own agent runtime, I looked at most of the off-the-shelf platforms out there. Everybody is selling roughly the same bundle right now: durable execution, sandboxes, tool approvals, memory, evals, chat channels.
My quick notes on what I looked at:
- Cloudflare Agents: TypeScript on Durable Objects with scheduling, sandboxes, approvals.
- Mastra: nice TypeScript DX, suspend/resume workflows, memory, evals.
- LangGraph + LangSmith: mature option for stateful graphs, human-in-the-loop, tracing.
- Anthropic Managed Agents: good sandbox, session log, and MCP setup, tied to Claude.
- OpenAI Agents SDK: lightweight loop + tools +
SandboxAgent, doesn’t force a hosting platform. - Eve by Vercel: TypeScript durable workflows, sandboxes, OAuth/approvals on Vercel (still beta).
- Cloudflare OS: open-source workspace running code in V8 isolates instead of full Linux containers.
- Google ADK and Microsoft Agent Framework + Durable Task: makes sense if you’re already all-in on GCP or Azure.
- CrewAI + AMP: Python multi-agent flows.
- Composable stacks like PydanticAI + Temporal, Inngest AgentKit, hosted sandboxes like E2B.
I didn’t want to buy into an all-in-one vendor platform. I wanted something small we own completely and can swap pieces out of later.
For v1, every task (triggered by API, webhook, cron, or chat) maps to one durable Agent Session with these fields:
Agent Session
├── objective
├── identity
├── context
├── capabilities
├── workspace
├── durable state
├── event history
├── artifacts
├── approvals
├── cost and limits
└── final result
My constraints for v1: OpenAI Agents SDK (SandboxAgent) for the inner tool loop, an ephemeral Docker container for the sandbox, skills loaded from plain markdown directories, memory stored in a read-only simple.md inside the container, explicit allowlists for tools and network, no subagents yet, and if an activity crashes and retries under the hood the user still sees one continuous session in the UI.
The input payload looks like this:
type AgentSessionInput = {
sessionId: string;
objective: string;
context?: {
text?: string;
files?: string[];
references?: string[];
};
skills: string[];
memoryFile?: string;
permissions: {
tools: string[];
networkAllowlist: string[];
writablePaths: string[];
requiresApproval: string[];
};
limits: {
timeoutSeconds: number;
maxModelTurns: number;
maxToolCalls: number;
cpu: number;
memoryMb: number;
};
model: {
name: string;
baseUrl?: string;
};
};
Single run inside Docker
Before touching Temporal, I got a single stateless run working cleanly inside an ephemeral Docker container:
TASK ─► SandboxAgent (Docker) ─► result
├── tools: read, search, shell, tests
├── Skills + simple.md (read-only)
└── /workspace: input ro · working rw · output rw
Inside the container, /workspace separates read-only inputs from writable scratch/output dirs:
/workspace/
├── input/ read-only
├── working/ writable
├── output/ writable
├── task.md read-only
├── simple.md read-only
└── skills/ read-only
simple.md is mounted read-only so the agent cannot overwrite its own long-term memory mid-run. If it wants to update memory, it proposes edits in its final output and a human or controller process decides what to keep.
Credentials stay out of the container completely - no API keys or GitHub tokens inside Docker. When the agent wants to call an external API or comment on a PR, it emits a tool request, and the trusted controller outside checks policy, asks a human for approval if needed, runs the call with a scoped token, and sends back only the sanitized response:
model requests tool ─► policy check ─► approval if needed
─► scoped credential ─► sanitized result back
For a PR review, the flow looks like this:
User requests PR review
│
▼
Trusted controller service
- verifies GitHub webhook
- fetches PR metadata
- checks out PR
- creates task.md
│
▼
Ephemeral Docker sandbox
- repository
- task.md
- review skill
- no GitHub credentials
- no network
│
▼
OpenAI SandboxAgent
- shell tool
- skills
- structured review output
│
▼
Trusted controller
- validates findings
- displays draft
- optionally publishes to GitHub
Wrapping the lifecycle in Temporal
Running SandboxAgent directly in Docker breaks as soon as the worker restarts mid-run, a task takes 2 hours, or the agent has to wait 14 hours for someone on Slack to approve a destructive action.
So I wrapped the whole lifecycle in a Temporal workflow (AgentSessionWorkflow):
AgentSessionWorkflow
CREATED
│
▼
prepareSession()
│
▼
provisionSandbox()
│
▼
runAgent()
│
├── approval required ──► WAITING_FOR_APPROVAL
│ │
│ ▼
│ resumeAgent()
│
▼
validateResult()
│
▼
persistArtifacts()
│
▼
destroySandbox()
│
▼
COMPLETED
Each box is a Temporal Activity:
prepareSession
- Resolve input files and context
- Load selected skills
- Load simple.md
- Calculate effective permissions
provisionSandbox
- Create ephemeral Docker container
- Mount workspace
- Apply CPU, memory and network restrictions
- Return sandbox ID
runAgent
- Start SandboxAgent
- Stream normalized events
- Execute allowed tool calls
- Return structured result
executeExternalTool
- Perform privileged calls outside the sandbox
- Use narrowly scoped credentials
- Apply approval rules
persistArtifacts
- Save output files, logs and structured results
destroySandbox
- Remove the container and temporary workspace
Human approval is a Temporal Signal. When the agent hits something in requiresApproval, the workflow pauses at WAITING_FOR_APPROVAL. Even if nobody responds for 3 days and worker pods redeploy twice in between, Temporal keeps the workflow state alive without holding a thread or polling a database.
Two choices saved a lot of headaches here:
First, I didn’t make every token or bash command a Temporal Activity. Temporal only owns the coarse boundaries (prepare -> provision -> run -> validate -> persist -> destroy). Inside runAgent, the SDK runs its normal loop and streams events out with sequence numbers so the UI stays live.
Second, I hid the OpenAI SDK behind a tiny AgentRunner interface:
interface AgentRunner {
run(
session: AgentSession,
environment: ExecutionEnvironment,
): AsyncIterable<AgentEvent>;
}
Right now AgentRunner wraps OpenAI’s SandboxAgent. Because Temporal, Docker, the skill loader, and approval signals only talk to AgentRunner, we can swap the inner loop later (Claude Agent SDK, Cloudflare runtime, self-hosted harness, whatever) without rewriting the control plane.
Models and SDKs keep churning every few months, so the parts worth investing in are the boundaries around them: sandboxes with zero credentials inside, scoped per-resource permissions, Temporal signals for approvals and crash recovery, and workflow-level cost/turn caps.
Companion post: three ways to put an LLM inside a Temporal workflow.