Agent 与自动化 4.0 · 优秀 2026-10-06 · 文章

What is Codemode

Pi 1.0 为 MCP 带来的答案 Codemode:工具调用不再把定义和输出塞进 context 让模型挑选,而是让模型在 harness 内的沙盒里写 JavaScript 来组合工具调用沙盒用 WASM 运行时里的 QuickJS,刻意限死网络文件系统和 timer内存受限,唯一出路是再调一次工具;大体量工具输出得以结构化吞吐而不必整段灌回 context,还能在一次调用里暂存状态给下一次用Codemode 在 Pi 里随 MCP 默认启用,也可用 defaultTools 的 +codemode 单独打开这是作者从 Code Is All You NeedMCP needs code 一路主张的具体工程落地

打开原文回到归档

What is Codemode

  • ID: 7510e7f8
  • 原文链接: https://lucumr.pocoo.org/2026/10/6/codemode/
  • 作者: Armin Ronacher (mitsuhiko)
  • 日期: 2026-10-06
  • 分类: agents
  • 来源类型: article
  • 标签: mcp, tool-use, sandbox, agent-harness, quickjs
  • 质量评分: 4/5
  • 抓取时间: 2026-10-07T15:52:52Z

中文导读

Armin Ronacher 在 Pi 1.0 里给出的 MCP 答案叫 Codemode:工具调用不走『定义进 context、模型挑一个』的老路,而是让模型在 harness 内的沙盒里写 JavaScript,用代码把工具调用组合起来。沙盒实现是 WASM 运行时里的 QuickJS,带刻意的限制:无网络、无文件系统、无 timer、内存受限,代码唯一能做的就是再调一次其他工具。这样做的直接收益是大体量输出可以结构化吞吐,而不必每次把后 2000 行灌回 context;调用之间可以暂存状态,也能并发触发工具。Codemode 在 Pi 里随 MCP 默认启用,也可以在设置里用 defaultTools 的 +codemode 单独打开。文章把这一定位为作者 2025 年 Code Is All You Need 与 MCP needs code 两篇主张的工程落地。

为什么值得关注

工具调用形态之争(MCP 定义进 context vs 代码组合)一年多来最具体的一份工程答案:沙盒边界(QuickJS/WASM、无网络无文件系统)和默认启用策略都是可复用的设计决策。

关键信息

  • 文章标题:What is Codemode;作者 Armin Ronacher;发布于 2026-10-06
  • 沙盒:Pi 用 WASM 运行时里的 QuickJS,无网络、无文件系统、无 timer、内存受限
  • Codemode 随 MCP 默认启用;也可用 defaultTools: ["+codemode"] 单独开启
  • 前序主张:Code Is All You Need (2025-07)、MCP needs code (2025-08)

English Abstract

With Pi 1.0 the author added MCP support via Codemode: instead of loading tool definitions and outputs into context, the model writes JavaScript in a harness-side sandbox (QuickJS in WASM, no network/file system/timers, limited RAM) whose only capability is calling other tools. This lets large outputs be consumed structurally and enables state stash and concurrency; Codemode is on by default in Pi when MCP is enabled.

English Summary

Codemode replaces context-loaded tool selection with sandboxed JS composition of tool calls in Pi 1.0; the sandbox forbids network, filesystem, and timers so tool calls are the only side channel, and large outputs no longer need to be dumped back into context.

Obsidian Notes

  • 内容获取路径:opencli web read --url https://lucumr.pocoo.org/2026/10/6/codemode/ 成功抓取全文(约 18.5 KB),沙盒限制与默认启用策略均出自正文。
  • 现代站点生成器按 content/{entry.id}.md 查找内容页;本文件写入 canonical content 目录,而不是 openclaw/content/。