Skip to content

Commit ec717f5

Browse files
mattzcareyelithrar
andauthored
@cloudflare/codemode v0.1.0: a new runtime agnostic modular architecture (#28473)
* Add @cloudflare/codemode v0.1.0 changelog entry * remove utils * Apply suggestion from @elithrar * Apply suggestion from @elithrar --------- Co-authored-by: Matt Silverlock <msilverlock@cloudflare.com>
1 parent ee30b7e commit ec717f5

1 file changed

Lines changed: 74 additions & 0 deletions

File tree

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
---
2+
title: "@cloudflare/codemode v0.1.0: a new runtime agnostic modular architecture"
3+
description: "The Code Mode SDK has been rewritten with `createCodeTool()`, `DynamicWorkerExecutor`, and a new `Executor` interface that allows for Bring Your Own (BYO) sandbox."
4+
products:
5+
- agents
6+
- workers
7+
date: 2026-02-20
8+
---
9+
10+
import { TypeScriptExample, WranglerConfig } from "~/components";
11+
12+
The [`@cloudflare/codemode`](https://www.npmjs.com/package/@cloudflare/codemode) package has been rewritten into a modular, runtime-agnostic SDK.
13+
14+
[Code Mode](https://blog.cloudflare.com/code-mode/) enables LLMs to write and execute TypeScript that orchestrates your tools, instead of calling them one at a time. This can (and does) yield significant token savings, reduces context window pressure and improves overall model performance on a task.
15+
16+
The new `Executor` interface is runtime agnostic and comes with a prebuilt `DynamicWorkerExecutor` to run generated code in a [Dynamic Worker Loader](/workers/runtime-apis/bindings/worker-loader/).
17+
18+
## Breaking changes
19+
20+
- Removed `experimental_codemode()` and `CodeModeProxy` — the package no longer owns an LLM call or model choice
21+
- New import path: `createCodeTool()` is now exported from `@cloudflare/codemode/ai`
22+
23+
## New features
24+
25+
- **`createCodeTool()`** — Returns a standard AI SDK `Tool` to use in your AI agents.
26+
- **`Executor` interface** — Minimal `execute(code, fns)` contract. Implement for any code sandboxing primitive or runtime.
27+
28+
### `DynamicWorkerExecutor`
29+
Runs code in a [Dynamic Worker](/workers/runtime-apis/bindings/worker-loader/). It comes with the following features:
30+
31+
- **Network isolation**`fetch()` and `connect()` blocked by default (`globalOutbound: null`) when using `DynamicWorkerExecutor`
32+
- **Console capture**`console.log/warn/error` captured and returned in `ExecuteResult.logs`
33+
- **Execution timeout** — Configurable via `timeout` option (default 30s)
34+
35+
## Usage
36+
37+
<TypeScriptExample>
38+
39+
```ts
40+
import { createCodeTool } from "@cloudflare/codemode/ai";
41+
import { DynamicWorkerExecutor } from "@cloudflare/codemode";
42+
import { streamText } from "ai";
43+
44+
const executor = new DynamicWorkerExecutor({ loader: env.LOADER });
45+
const codemode = createCodeTool({ tools: myTools, executor });
46+
47+
const result = streamText({
48+
model,
49+
tools: { codemode },
50+
messages,
51+
});
52+
```
53+
54+
</TypeScriptExample>
55+
56+
## Wrangler configuration
57+
58+
<WranglerConfig>
59+
60+
```jsonc
61+
{
62+
"worker_loaders": [{ "binding": "LOADER" }],
63+
}
64+
```
65+
66+
</WranglerConfig>
67+
68+
See the [Code Mode documentation](/agents/api-reference/codemode/) for full API reference and examples.
69+
70+
## Upgrade
71+
72+
```sh
73+
npm i @cloudflare/codemode@latest
74+
```

0 commit comments

Comments
 (0)