Live
Deploying OpenCode 2.0 with the Agents SDK: a Durable Object Harness on CloudflareGitHub adds durable push attribution to commits for Enterprise previewMultivariate Forecasting in BigQuery: TimesFM 3.0 Changes the Game for EngineersAI‑Assisted Development Doubles Spotify Change Rate, Triggering New Quality ControlsDocker Hub blocks automatic PAT transfer on account conversion and revokes legacy tokensSecond‑Edition SRE Practices: Dynamic SLOs, OpenTelemetry Observability, and Platform Automation for Modern WorkloadsDeploying Multi‑Node LLM Inference on EKS with Ray LLM ContainersImplementing Global Cross‑Region Inference for OpenAI GPT‑6 on Amazon BedrockDeploying OpenCode 2.0 with the Agents SDK: a Durable Object Harness on CloudflareGitHub adds durable push attribution to commits for Enterprise previewMultivariate Forecasting in BigQuery: TimesFM 3.0 Changes the Game for EngineersAI‑Assisted Development Doubles Spotify Change Rate, Triggering New Quality ControlsDocker Hub blocks automatic PAT transfer on account conversion and revokes legacy tokensSecond‑Edition SRE Practices: Dynamic SLOs, OpenTelemetry Observability, and Platform Automation for Modern WorkloadsDeploying Multi‑Node LLM Inference on EKS with Ray LLM ContainersImplementing Global Cross‑Region Inference for OpenAI GPT‑6 on Amazon Bedrock
Cloudflare

Deploying OpenCode 2.0 with the Agents SDK: a Durable Object Harness on Cloudflare

AI SummaryPowered by AI

The Agents SDK now ships an experimental OpenCodeHarness that runs OpenCode 2.0 inside a plain Durable Object with SQLite‑backed sessions and lifecycle recovery. This lets AI and platform engineers combine Workers AI bindings with OpenCode plugins while exposing new operational constraints around evictions and experimental APIs.

The latest Agents SDK release adds an experimental OpenCodeHarness that lets you execute OpenCode 2.0 inside a plain Durable Object. Sessions are persisted in an embedded SQLite database and a lifecycle job can restart work that was interrupted by object eviction. For teams that already use Workers AI, this creates a single‑runtime pattern for running large‑language‑model‑driven agents on Cloudflare’s edge.

OpenCode Harness Overview

The harness is marked experimental, meaning the API surface may change and official support is limited. It wraps OpenCode’s runtime inside a Durable Object, exposing two key behaviours:

  • State is stored locally in SQLite, giving each user a lightweight session store without external dependencies.
  • A background lifecycle job monitors eviction events and re‑queues any in‑flight work, allowing the object to recover after Cloudflare’s automatic memory reclamation.

Because the harness runs in a plain Durable Object, it does not rely on any of the higher‑level Agent constructs such as scheduled workflows or built‑in tool runners.

Integration with Workers AI and Plugins

The provider path agents/models/opencode connects the harness to Workers AI through the AI binding. This binding forwards model calls directly to the Workers AI service, letting the OpenCode engine use the same inference endpoint as other Cloudflare AI workloads.

OpenCode plugins can be added to the harness to supply custom tools, remote MCP servers, or domain‑specific skills. The plugin model is unchanged from the standard OpenCode SDK; the only difference is that the host API is now the Cloudflare‑specific embedded interface documented in the OpenCode Cloudflare SDK guide.

Operational and Security Implications

Running an experimental harness inside a Durable Object introduces several considerations:

  • Eviction handling: While the lifecycle job attempts to resume interrupted sessions, there is no guarantee of exactly‑once execution. Practitioners should design idempotent tool calls and be prepared for occasional duplicate work.
  • Session isolation: Each Durable Object instance holds its own SQLite file. Access control must be enforced at the application layer; the harness does not provide built‑in authentication.
  • Prompt quotas: Workers AI enforces per‑account limits. Adding a quota check before forwarding a prompt can prevent unexpected throttling.
  • Unsupported local tools: The experimental harness does not support the full set of OpenCode local tools. Any tool that requires external binaries or OS‑level access should be removed or replaced with a remote plugin.
  • Versioning: The harness requires Agents SDK 0.28.0 or later together with the OpenCode packages. Upgrading the SDK may introduce breaking changes to the experimental API.

Related CloudNinjas coverage: AI engineering.

What This Means For Practitioners

Adopting the OpenCode harness gives you a low‑overhead path to run LLM‑driven agents at the edge, but you must treat it as a prototype rather than production‑grade code. Evaluate the following before committing:

  1. Confirm that your workload can tolerate occasional duplicate execution caused by eviction recovery.
  2. Implement explicit authentication and prompt‑quota checks around the AI binding.
  3. Validate that all required tools are available as remote plugins, since local tool execution is not supported.
  4. Monitor SDK releases for changes to the experimental API and plan for migration.

When those constraints are acceptable, the OpenCode harness provides a concise architecture: a single Durable Object per user session, SQLite persistence, and direct Workers AI inference—all managed through the Agents SDK.

Originally published atCloudflare Developer Platform