← Back
Cloudflare
Cloudflare releases @cloudflare/codemode v0.1.0 with runtime-agnostic modular architecture
Cloudflare WorkersCloudflare · releasesdkbreaking-changefeatureapi · developers.cloudflare.com ↗

@cloudflare/codemode v0.1.0 Release

Cloudflare has completely rewritten the @cloudflare/codemode package with a new modular, runtime-agnostic architecture. Code Mode enables LLMs to write and execute code that orchestrates your tools in batches, rather than calling them one at a time. This approach yields significant token savings, reduces context window pressure, and improves overall model performance on tasks.

Key Changes

Breaking Changes:

  • experimental_codemode() and CodeModeProxy have been removed — the package no longer owns LLM calls or model selection
  • New import path: createCodeTool() is now exported from @cloudflare/codemode/ai (previously imported from the main package)

New APIs:

  • createCodeTool() — Returns a standard AI SDK Tool for use in AI agents, decoupling the SDK from specific LLM implementations
  • Executor interface — A minimal execute(code, fns) contract that allows developers to implement custom code execution for any sandboxing primitive or runtime

DynamicWorkerExecutor

The SDK includes a prebuilt DynamicWorkerExecutor designed for running generated code in Cloudflare's Dynamic Worker Loader. It provides:

  • Network isolationfetch() and connect() are blocked by default when using globalOutbound: null
  • Console captureconsole.log, warn, and error outputs are captured and returned in ExecuteResult.logs
  • Configurable execution timeout — Default 30 seconds, adjustable via options

Getting Started

import { createCodeTool } from "@cloudflare/codemode/ai";
import { DynamicWorkerExecutor } from "@cloudflare/codemode";
import { streamText } from "ai";

const executor = new DynamicWorkerExecutor({ loader: env.LOADER });
const codemode = createCodeTool({ tools: myTools, executor });
const result = streamText({
  model,
  tools: { codemode },
  messages,
});

Wrangler configuration requires adding a worker loader binding:

[[worker_loaders]]
binding = "LOADER"

Migration Path

To upgrade, run npm i @cloudflare/codemode@latest. Refer to the Code Mode documentation for complete API reference and examples.