Skip to content

Cloudflare lets you run a coding agent inside a Durable Object

The Agents SDK adds an experimental OpenCodeHarness that runs OpenCode 2.0 with SQLite-backed sessions that survive eviction.

Source: Cloudflare

Cloudflare’s Agents SDK now has an experimental OpenCodeHarness that runs OpenCode 2.0, an AI coding agent framework, directly inside a standard Durable Object. Sessions are stored in SQLite, and Lifecycle jobs resume interrupted work after the Durable Object gets evicted, so a long-running coding task does not just vanish if the instance is reclaimed.

Setup is npm i agents@latest @opencode/sdk@2 @opencode/plugin@2, then a Durable Object class instantiates the harness with a model, plugins and default agent behaviour. Cloudflare’s own example wires it to @cf/moonshotai/kimi-k2.7-code with low reasoning effort via the agents/models/opencode provider, which routes through a Workers AI binding rather than an external API key.

const harness = new OpenCodeHarness({
  model: "agents/models/opencode:@cf/moonshotai/kimi-k2.7-code",
  reasoningEffort: "low",
})
const result = await harness.ask(prompt)

Plugins can add custom tools and remote MCP servers, and ask() returns status, text and reasoning together.

Why it matters: running a coding agent usually means managing your own process, state and retries. Doing it in a Durable Object gets you persistence and resumability for free, and billing stays inside Workers AI instead of a separate model API bill.

The caveat: this is explicitly experimental, and the model binding only covers what Workers AI hosts, not every model OpenCode normally supports.

Share

Related reading

More from The Wire

All briefs