Skip to content

An open-source, faster Devin alternative

TypeScript

docs(runtimes): runtime model = brain server + OC-managed adapter (reshape)

Igor Zalutskie4b5e7517905
diff --git a/docs/agent-sessions/custom-runtimes.mdx b/docs/agent-sessions/custom-runtimes.mdx
index 581882f0..8f560d1d 100644
--- a/docs/agent-sessions/custom-runtimes.mdx
+++ b/docs/agent-sessions/custom-runtimes.mdx
@@ -1,35 +1,118 @@
---
mode: "wide"
title: "Custom runtimes"
-description: "Package any agent harness as a runtime (coming soon)"
+description: "Package your own agent harness as a runtime (coming soon)"
---
-<Note>**Planned.** This page describes planned API shape, not shipped behavior. Today the built-in [runtimes](/agent-sessions/runtimes) are `claude` and `codex`; bringing your own is on the roadmap.</Note>
+<Note>**Planned.** This page describes the intended custom-runtime contract, not shipped behavior. Today the built-in [runtimes](/agent-sessions/runtimes) are `claude` and `codex`; bringing your own runtime is on the roadmap.</Note>
-A custom runtime is a container image for your own agent harness — anything beyond the built-in `claude` and `codex` runtimes. Once registered, select it per agent with `runtime: "<name>"`; sessions, events, steering, and webhooks work the same way.
+A custom runtime lets you run your own agent harness on Durable Agent Sessions. Once registered, you select it on an agent with `runtime: "<name>"`; sessions, events, steering, webhooks, recovery, and sandbox tools work the same way as the built-ins.
-The built-in runtimes are themselves thin wrappers around a provider's agent SDK (the Claude Agent SDK, the OpenAI Codex SDK) that conform to the contract below — a custom runtime is the same idea around any harness or SDK you choose. See [example runtimes](https://github.com/diggerhq/oc-runtime-examples) for working `claude` and `codex` wrappers.
+The runtime image contains a **brain server**: a resident process around your agent SDK. OpenComputer supplies the platform adapter that reads the session log, owns fencing and idempotency, exposes tools, calls your brain over localhost, and commits the brain's stream as durable events.
-## Runtime invocation
+You implement the brain. You do **not** implement OpenComputer's event API, session cursors, turn-token auth, sandbox HTTP calls, or webhook delivery.
-For each turn, the platform starts your image with the session id, read cursor, events API URL, and a fenced **turn token**. The image must:
+See [example runtimes](https://github.com/diggerhq/oc-runtime-examples) for minimal `claude` and `codex` brain servers.
-1. read the new input from the [event log](/agent-sessions/events) at the cursor;
-2. drive its own agent loop;
-3. stream events back over the authenticated events API;
-4. perform side effects through the remote [sandbox tools](/agent-sessions/runtime-tools);
-5. exit 0 when it has nothing left to do.
+## Runtime shape
-The turn token is fenced: writes from a superseded runtime instance are rejected. Non-zero exit is treated as a crash and the platform restarts the turn in place.
+Your image starts an HTTP server on `127.0.0.1:$OC_BRAIN_PORT` (`8080` by default). The server stays warm across turns and handles one turn at a time.
-## Journal and recovery
+```http
+GET /healthz
+```
-The image should be stateless. Store resumable state in the provided journal directory. The durable record is the event log plus that journal, so crashes, idle hibernation, and machine restore follow the same [recovery](/agent-sessions/runtimes#failure-behavior) behavior as `claude`.
+```json
+{
+ "status": "ready",
+ "contract_version": "oc-runtime-http-2026-06-22",
+ "busy": false
+}
+```
-## Model configuration
+Return `busy: true` while a turn is running. A second turn should return `409`; OpenComputer already serializes real turns, so this is a safety check.
-The model is configuration, not part of the image. A runtime declares which providers it can drive; switching providers requires a runtime image that supports the target provider.
+## Turn request
+
+For each turn, the adapter sends the new input and run config:
+
+```http
+POST /turn
+Content-Type: application/json
+```
+
+```json
+{
+ "contract_version": "oc-runtime-http-2026-06-22",
+ "turn_id": "turn_...",
+ "input": [
+ { "role": "user", "content": "Review this repository." }
+ ],
+ "config": {
+ "model": "anthropic/claude-opus-4-8",
+ "system_prompt": "Run tests and explain risks.",
+ "mcp_endpoint": "http://127.0.0.1:4317/mcp",
+ "state_dir": "/home/sandbox/.oc/runtime-state"
+ },
+ "deadline_s": 600
+}
+```
+
+The adapter has already read the event log. Your brain receives the new turn input, not a session cursor.
+
+## Step stream
+
+`POST /turn` responds with newline-delimited JSON. Each line is one step:
+
+```jsonl
+{"seq":1,"kind":"message","visibility":"progress","text":"Reading files..."}
+{"seq":2,"kind":"message","visibility":"progress","text":"Running tests..."}
+{"seq":3,"kind":"done","reason":"quiescent"}
+```
+
+The adapter maps these steps to [session events](/agent-sessions/events), assigns stable idempotency keys, and flushes committed output before ending the turn.
+
+Core step kinds:
+
+| Step | Purpose |
+| --- | --- |
+| `message` | Activity from the agent. Use `say` or `ask` for human-visible output. |
+| `done` | Terminal step. `reason` is `quiescent`, `awaiting_input`, or `error`. |
+
+Tool calls, including user-visible `say` and `ask`, are made through MCP, not by emitting HTTP requests to OpenComputer.
+
+## Tools
+
+The adapter exposes tools at `config.mcp_endpoint`. Your brain connects through your SDK's MCP support.
+
+| Tool | What it does |
+| --- | --- |
+| `bash` | Run a shell command in the hands sandbox. |
+| `read` | Read a file from the hands sandbox. |
+| `write` | Write a file in the hands sandbox. |
+| `ls` | List a directory in the hands sandbox. |
+| `say` | Emit a user-visible message. |
+| `ask` | Ask for input and end the turn awaiting a reply. |
+
+The brain sandbox is for the model loop. The hands sandbox is where files and commands run.
+
+## State and recovery
+
+Store resumable state under `config.state_dir`. OpenComputer checkpoints that directory at turn boundaries and restores it after recovery.
+
+Examples:
+
+- Claude writes a local journal and continues from it.
+- Codex persists a server-side thread id and resumes that thread.
+
+Design your brain so replay is safe. If a crash happens after a step is emitted but before the turn finishes, the adapter may replay from durable state and dedupe already committed events.
## Register runtimes
-Register a runtime with `oc runtime push <image>` and select it with `runtime: "<name>"`. Runtimes are versioned; each session pins the version it starts with, so pushing a new build never changes in-flight sessions.
+Registration is planned:
+
+```bash
+oc runtime push
+```
+
+Runtimes will be versioned. Each session pins the runtime build it starts with, so publishing a new build affects new sessions only.
diff --git a/docs/agent-sessions/overview.mdx b/docs/agent-sessions/overview.mdx
index cda6bef0..85d99d8b 100644
--- a/docs/agent-sessions/overview.mdx
+++ b/docs/agent-sessions/overview.mdx
@@ -48,10 +48,10 @@ Give an agent a prompt and a task; OpenComputer runs it on a managed runtime and
## Architecture
<Frame>
- <img src="/images/durable-agent-sessions-architecture.svg" alt="Durable Agent Sessions architecture: your app starts/steers and streams a durable event-log session; a runtime (the brain) reads and appends to it and acts in a sandbox (the hands); the model runs on your key from the secret store, which never enters a sandbox; user-level events are delivered out via your webhook." />
+ <img src="/images/durable-agent-sessions-architecture.svg" alt="Durable Agent Sessions architecture: your app starts, steers, and streams a durable event-log session; a managed runtime adapter commits events while the brain drives the agent loop and acts through the hands sandbox; the model runs on your key from the secret store, which never enters a sandbox; user-level events are delivered out via your webhook." />
</Frame>
-The event log is the durable record. Your app starts sessions, streams events, and steers with messages. The runtime reads and appends to the log, drives the hands sandbox for file and command work, and delivers user-level events to your webhook. Your model key stays in the secret store.
+The event log is the durable record. Your app starts sessions, streams events, and steers with messages. The runtime drives the agent loop, acts through the hands sandbox for file and command work, and commits user-level events for webhook delivery. Your model key stays in the secret store.
## Use cases
diff --git a/docs/agent-sessions/runtimes.mdx b/docs/agent-sessions/runtimes.mdx
index 4062b271..35693809 100644
--- a/docs/agent-sessions/runtimes.mdx
+++ b/docs/agent-sessions/runtimes.mdx
@@ -55,25 +55,32 @@ The runtime, model, and credential have to agree: `runtime: "codex"` needs an `o
The model is configuration, not part of the runtime image. Each runtime drives one provider — `claude` drives Anthropic, `codex` drives OpenAI — and you choose the exact `provider/model` and the key it runs on. Because the model is config, the rest of your integration is identical across runtimes; the runtime is the one thing that changes.
-A runtime is a thin **wrapper around a provider's agent SDK**: `claude` wraps the **Claude Agent SDK**, `codex` wraps the **OpenAI Codex SDK**. The wrapper does the same small job in both cases — read the new input, drive the SDK's loop, translate each step into [session events](/agent-sessions/events), act only through the [sandbox tools](/agent-sessions/runtime-tools), and exit when there's nothing left to do. The built-in runtimes are built exactly this way, and a [custom runtime](/agent-sessions/custom-runtimes) is the same wrapper around any harness you choose. See [example runtimes](https://github.com/diggerhq/oc-runtime-examples) for `claude` and `codex` side by side — the platform-facing code is identical; only the SDK differs.
+A runtime has two pieces:
+
+- the **brain**, a resident server around the provider's agent SDK;
+- the **adapter**, managed by OpenComputer, which connects that brain to the durable session log.
+
+The brain knows the SDK, the model, the prompt, its resumable state directory, and the sandbox tools exposed to it. It does **not** write OpenComputer events directly and does not call the sandbox API itself. The adapter reads new input from the [event log](/agent-sessions/events), sends a bounded turn to the brain, translates the brain's stream into session events, handles fencing/idempotency, and only declares the turn done after committed output is durable.
+
+The built-in runtimes are built this way, and [custom runtimes](/agent-sessions/custom-runtimes) follow the same split. See [example runtimes](https://github.com/diggerhq/oc-runtime-examples) for `claude` and `codex` brain servers side by side.
A runtime also **starts fast**: the engine is prepared ahead of time and baked into the image, so a new or recreated session doesn't wait on a per-session download before its first step.
### Brain and hands sandboxes
-The runtime runs the agent loop in its **own per-session sandbox** (the *brain*). The agent's file and shell tools don't run there — they run in a **separate sandbox** (the *hands*) that the brain drives through remote tools, so the model has no local disk or network of its own: the sandbox is the only surface it can act through. The brain carries the [sealed model key](/agent-sessions/authentication#model-credentials) (egress-allowlisted to the model API, swapped in by a host proxy so the key never enters the VM); the hands sandbox holds no secrets at all.
+The runtime runs the agent loop in its **own per-session sandbox** (the *brain*). The agent's file and shell tools don't run there — they run in a **separate sandbox** (the *hands*) exposed to the brain through tools, so commands and file edits stay isolated from the model loop. The brain carries the [sealed model key](/agent-sessions/authentication#model-credentials) (egress-allowlisted to the model API, swapped in by a host proxy so the key never enters the VM); the hands sandbox holds no secrets.
-### Each turn is one bounded run
+### Each turn is bounded
-A turn is one bounded, invoke-style run — it:
+A turn is one bounded request from the adapter to the brain:
-1. reads the new input from the [event log](/agent-sessions/events) at the cursor,
-2. drives the runtime's agent loop,
-3. **streams every step back as events** over the authenticated events API,
-4. performs side effects only through the remote [sandbox tools](/agent-sessions/runtime-tools) (`bash` / `read` / `write` / `ls`, plus `say` / `ask`), and
-5. **exits when it has nothing left to do** — it yields rather than busy-waits, so time spent waiting costs no compute.
+1. the adapter reads new input from the [event log](/agent-sessions/events);
+2. it sends that input, the model, prompt, tool endpoint, and state directory to the brain;
+3. the brain drives the provider SDK and acts only through [runtime tools](/agent-sessions/runtime-tools);
+4. the adapter commits the brain's stream as session events with stable ids;
+5. the turn ends when the brain returns `done`, asks for input, hits a deadline, or crashes.
-Across turns it continues an on-box **journal**; the durable record is the event log *plus* that journal, which the platform checkpoints at each boundary and restores on recovery (see [Failure behavior](#failure-behavior)).
+Across turns the brain keeps provider-specific state under a checkpointed state directory — for example a local Claude journal or a Codex thread id. The durable record is the event log plus that state directory, which the platform checkpoints at each boundary and restores on recovery.
### Pinned per session
@@ -83,10 +90,11 @@ When a session starts it pins the runtime and version it began on (alongside the
Sessions are fully managed — you never restart anything yourself:
-- **One writer at a time.** Only one runtime instance advances a session at any moment; a stale or slow instance that returns after it was replaced is rejected, so a session never has two concurrent writers and the log never forks.
-- **A lost machine is picked back up.** If the machine running a turn dies, the turn is continued from where it left off, not restarted from scratch.
-- **Crash, hang, lost machine.** A bad exit restarts the turn in place (bounded retries); a hung turn is cut off by a **deadline** and ends `deadline_exceeded`; a lost machine is recreated and **restored from its last checkpoint**. Full matrix [below](#failure-behavior).
-- **A turn that can't start fails cleanly.** If the model key can't be resolved or the runtime image can't be fetched, the turn ends with an **`error` event carrying the reason** and the session returns to idle — it doesn't hang.
+- **One writer at a time.** Only one adapter advances a session at any moment; a stale or slow writer is rejected, so the log never forks.
+- **The brain is supervised.** If the resident brain crashes or stops answering health checks, it is restarted and the turn is retried from durable state.
+- **Hangs are bounded.** A turn has a deadline; a stuck model or tool path ends `deadline_exceeded` instead of staying stuck.
+- **A lost machine is restored.** If the brain sandbox is lost, OpenComputer recreates it, restores the checkpointed state directory, and replays from the durable log.
+- **A turn that can't start fails cleanly.** If the model key can't be resolved or the runtime image can't start, the turn ends with an **`error` event carrying the reason** and the session returns to idle — it doesn't hang.
- **Nothing gets stranded.** A periodic safety sweep picks up any session whose work was missed or left mid-flight, so nothing stays stuck silently.
- **Everything is recorded.** Every turn and sandbox transition is logged, so you can see where a session is and why a turn ended the way it did.
@@ -98,12 +106,12 @@ What's guaranteed today, and what isn't:
| --- | --- |
| Client disconnects | Reconnect from your cursor ([events](/agent-sessions/events)); nothing lost. |
| Session idles | Sandbox hibernates; resumes intact on the next message. |
-| Runtime **crashes** | Auto-restarted in place; continues from the on-box journal. |
-| Runtime **hangs** | Bounded by the turn deadline; the turn ends `deadline_exceeded` — steer to continue. |
-| Sandbox lost **while idle** | Recreated from the last checkpoint. |
-| Sandbox lost **mid-turn** | That turn re-runs from the log. |
+| Brain **crashes** | Restarted; the turn resumes from committed events and checkpointed state. |
+| Brain **hangs** | Bounded by the turn deadline; the turn ends `deadline_exceeded` — steer to continue. |
+| Sandbox lost **while idle** | Recreated from the last checkpoint before the next turn. |
+| Sandbox lost **mid-turn** | Recreated, restored from checkpointed state, and replayed from the durable log. |
-Work since the last journaled step may repeat, so **make side effects idempotent** and treat the event log (and delivered webhooks) as the durable record. Uncommitted hands-sandbox files are not restored after sandbox loss — commit or push to keep them. Byte-exact **mid-turn** resume is coming in a later release.
+Work since the last committed step may repeat, so **make side effects idempotent** and treat the event log (and delivered webhooks) as the durable record. Uncommitted hands-sandbox files are not restored after sandbox loss — commit or push to keep them. Byte-exact **mid-turn** resume is coming in a later release.
## What's coming