← Back
Cloudflare
Cloudflare releases @cloudflare/codemode v0.1.0 with modular, runtime-agnostic SDK
Cloudflare Workers · releasesdkfeaturebreaking-changeapi · developers.cloudflare.com ↗

Overview

The @cloudflare/codemode package has undergone a complete rewrite to provide a modular, runtime-agnostic SDK for Code Mode—a feature that enables LLMs to write and execute code that orchestrates tools instead of calling them sequentially. This approach yields significant token savings, reduces context window pressure, and improves overall model performance.

Breaking Changes

The rewrite introduces several breaking changes developers must be aware of:

  • Removed experimental_codemode() and CodeModeProxy — The package no longer owns LLM calls or model selection
  • New import pathcreateCodeTool() is now exported from @cloudflare/codemode/ai (previously integrated differently)

New Architecture

The SDK introduces a minimal Executor interface with a simple execute(code, fns) contract, allowing implementation for any code sandboxing primitive or runtime. This design enables developers to bring their own execution environments.

The DynamicWorkerExecutor is the prebuilt implementation for Cloudflare Workers, offering:

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

Getting Started

The new createCodeTool() returns a standard AI SDK Tool for use in AI agents. Basic integration requires:

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 });

Configure your wrangler.toml or wrangler.jsonc with a worker loader binding:

[[worker_loaders]]
binding = "LOADER"

Action item: Update to @cloudflare/codemode@latest and refactor code that uses the removed experimental_codemode() function. See the Code Mode documentation for full API reference and migration examples.