Code Mode (programmatic tool calling)
intermediate resultmatched record
- Same query over the same API records.
- JSON tool loop: intermediate results transit the context.
- Code Mode: a script filters inside a sandboxed runtime.
- Only the final return value enters context.
Notes & references
Use when
Pagination, joins, filtering and multi-tool composition.
Avoid
Single small calls, or no isolated runtime.
// written by the model, run once in the sandbox
const orders = await shop.listOrders({ month: "May" });
const late = orders
.filter(o => o.status === "late")
.slice(0, 3);
return late; // only this reaches the model
- Code Mode: the better way to use MCPCloudflare
- Code execution with MCPAnthropic
- Code Mode: an entire API in 1,000 tokensCloudflare
- Executable Code Actions Elicit Better LLM AgentsWang et al.
- Making Claude Code safer with sandboxingAnthropic