Skip to content

Commit 096b869

Browse files
committed
docs: reorganize code mode intro, add MCP Toolkit tip, move benefits earlier
1 parent e3b2d0d commit 096b869

1 file changed

Lines changed: 12 additions & 12 deletions

File tree

docs/use-cases/code-mode.mdx

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,18 @@ icon: "code"
88
Full working example with SecureExecExecutor and tool dispatch.
99
</Card>
1010

11-
Instead of calling tools one at a time (requiring round-trips through the LLM), Code Mode gives the agent a single "execute code" tool. The LLM writes JavaScript that chains multiple tool calls in one shot, and Secure Exec runs it in an isolated V8 sandbox.
11+
Instead of calling MCP tools one at a time, Code Mode lets the LLM write JavaScript that orchestrates everything in one go — run safely in a V8 sandbox by Secure Exec.
1212

13-
This pattern, introduced by [Cloudflare's Code Mode](https://blog.cloudflare.com/code-mode/), works because LLMs are better at writing code than calling tools. They have millions of lines of real-world code in their training data but limited exposure to synthetic tool-calling formats.
13+
<Tip>
14+
[MCP Toolkit](https://mcp-toolkit.nuxt.dev/advanced/code-mode) provides a premade Code Mode library powered by Secure Exec: `experimental_codeMode: true`. We recommend trying it first. The rest of this page covers how to implement Code Mode yourself.
15+
</Tip>
16+
17+
## Why Code Mode
18+
19+
- **[81% less token overhead](https://x.com/hugorcd/status/2034616192225407273)**: With 50 tools, replacing per-call tool descriptions with a single code-execution tool cuts tool description tokens by 81%
20+
- **Fewer round-trips**: Chain multiple tool calls, conditionals, and data transformations in a single execution
21+
- **Real control flow**: Loops, branching, `Promise.all` — not a chain of isolated tool calls
22+
- **Drop-in replacement**: Your existing tools don't change at all. Code Mode wraps them transparently.
1423

1524
## How it works
1625

@@ -72,18 +81,9 @@ Three tool calls, one sandbox execution, zero extra LLM round-trips.
7281

7382
See the [full working example](https://github.com/rivet-dev/secure-exec/tree/main/examples/code-mode) for the complete implementation including the `SecureExecExecutor`.
7483

75-
## Why Code Mode
76-
77-
- **Fewer round-trips**: Chain multiple tool calls, conditionals, and data transformations in a single execution
78-
- **Lower token usage**: Intermediate results stay in the sandbox instead of passing back through the LLM context
79-
- **Better tool handling**: LLMs manage more tools and greater complexity when presented as TypeScript APIs vs. raw tool definitions
80-
81-
## Status
82-
83-
Code Mode support in Secure Exec is early. Today you need to copy the [`SecureExecExecutor` adapter](https://github.com/rivet-dev/secure-exec/tree/main/examples/code-mode) from the example into your project. We're planning official first-party support.
84-
8584
## Further reading
8685

86+
- [Complete Code Mode implementation guide](https://mcp-toolkit.nuxt.dev/advanced/code-mode) — end-to-end Code Mode walkthrough using MCP Toolkit
8787
- [Cloudflare Code Mode blog post](https://blog.cloudflare.com/code-mode/)
8888
- [`@cloudflare/codemode` package](https://github.com/cloudflare/agents/tree/main/packages/codemode)
8989
- [AI Agent Code Exec](/use-cases/ai-agent-code-exec) for simpler single-tool execution patterns

0 commit comments

Comments
 (0)