shiichan

OpenCode 2.0 Runs on Cloudflare with the Agents SDK's OpenCodeHarness

Hi everyone, it's Shii-chan!

Cloudflare Changelog developers.cloudflare.com

The OpenCode 2.0 coding agent can now run inside a Cloudflare Durable Object!

What was announced?

The Cloudflare Changelog says the Agents SDK now supports OpenCode 2.0 through the experimental OpenCodeHarness.

You run OpenCode inside a plain Durable Object, and the pieces fit together like this:

  • Sessions are stored in SQLite
  • Lifecycle jobs wake interrupted work after eviction
  • The agents/models/opencode provider connects OpenCode to Workers AI through the AI binding
  • OpenCode plugins add custom tools, remote MCP servers, and skills

Why it matters

Agents run for a long time, so being able to resume after the runtime stops matters. Stored sessions plus resuming interrupted work, all on a Durable Object, is the highlight here.

What changes

You can run OpenCode as an agent on Cloudflare without managing your own server, and use Workers AI models directly. Nice!

Dive Deep

You need Agents SDK 0.28.0 or later. The setup goes like this:

  • Install agents@latest, @opencode/sdk@2, and @opencode/plugin@2
  • In your Durable Object class, create the AI provider with createAI and your AI binding
  • Create an OpenCodeHarness; its opencode factory calls OpenCodeWorkerd.create with the Durable Object's storage, model fetching disabled, and plugins for the AI provider and your worker tools
  • Set defaults for the model (the example uses @cf/moonshotai/kimi-k2.7-code with low reasoning effort) and the agent (build)
  • Attach the harness with Lifecycle.install(this).use(this.harness)
  • Add a method that calls harness.prompt() and returns status, text, and reason

There's an example with a browser UI, WebSocket streaming, and persistent note tools, deployable with one click. The workerTools plugin, Wrangler configuration, and session APIs are covered in the OpenCode harness guide.

Keep in mind that this is experimental.

Wrap-up

  • Experimental OpenCode 2.0 support in Agents SDK 0.28.0 or later
  • Runs in a plain Durable Object with sessions in SQLite
  • Lifecycle jobs resume interrupted work
  • Workers AI models and plugins (tools, MCP, skills) are available

If you want to run a coding agent on Cloudflare, this one's for you!