Cloudflare releases @cloudflare/codemode v0.1.0 with runtime-agnostic modular architecture
@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()andCodeModeProxyhave 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 SDKToolfor use in AI agents, decoupling the SDK from specific LLM implementationsExecutorinterface — A minimalexecute(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 isolation —
fetch()andconnect()are blocked by default when usingglobalOutbound: null - Console capture —
console.log,warn, anderroroutputs are captured and returned inExecuteResult.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.