Skip to content

feat(agent-runtime): add opt-in sandboxed codemode tool - #2511

Merged
vastsa merged 1 commit into
mainfrom
feat/codemode-sandbox
Nov 21, 2026
Merged

vastsa merged 1 commit into
mainfrom
feat/codemode-sandbox

Conversation

@vastsa

@vastsa vastsa commented Nov 21, 2026

Copy link
Copy Markdown
Owner

Summary

Implements #2498: an opt-in codemode tool that runs model-written JavaScript in a QuickJS-WASI worker (@earendil-works/pi-codemode) and returns only the script output to the model.

  • Narrow adapter in packages/agent-runtime/src/codemode/; no AgentSession.
  • Nested tools.* calls go through runToolCall with the session's own hooks: Host permission/approval, ToolSearch activation, mode policy, extension hooks, file admission, cancellation (tools.abort). Only active tools are callable; control/delegation tools are excluded; Read/Glob/Grep may overlap, everything else is serialized.
  • Limits: 256 MiB heap, 64 KiB source, 120 s / 600 s deadline, 256 nested calls, bounded output, 2 workers per sidecar.
  • Lineage via nestedParentToolCallId (never parentToolCallId); nested rows are excluded from rebuilt model context; delegates do not inherit codemode.
  • models.list/complete/classify/generateImages expose allowlisted metadata only; each physical request emits identified usage attributed to its starting turn.
  • Sidecar bundle ships chunks/codemode-worker.js + chunks/quickjs.wasm; a packaged test runs a script outside node_modules.
  • Setting codemodeEnabled (default off, Agent only) with Settings UI and 9 locales.
  • ADR docs/adr/codemode-sandbox-boundary.md, spec and E2E plan updates.

Validation

  • agent-runtime typecheck + vitest (2113 pass; one unrelated system-ca timeout passed on rerun)
  • shared vitest 1460 pass; desktop typecheck; related desktop node tests incl. isolated Electron settings test
  • biome lint, check:pi-dependencies

fixes #2498

Multi-step investigations and chains of MCP calls cost one model round
trip per call and put every intermediate result into the context. The
new codemode tool runs a short model-written script in a QuickJS-WASI
worker so tools can be batched, chained and filtered locally, and only
the script's output reaches the model.

The sandbox holds no host function or credential. Each nested call goes
through pi-agent-core runToolCall with the session's own hooks, so
ToolSearch activation, mode policy, extension hooks, Host permission and
approval, audit and cancellation are those of a direct call. Lineage uses
nestedParentToolCallId, auxiliary model calls record identified usage,
and the sidecar bundle ships the worker and WASM. The feature is off by
default (Settings -> Agent behavior -> Execution, Agent mode only).

fixes #2498
@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying pi-desktop with  Cloudflare Pages  Cloudflare Pages

Latest commit: 458f5c9
Status: ✅  Deploy successful!
Preview URL: https://87b74eff.pi-desktop.pages.dev
Branch Preview URL: https://feat-codemode-sandbox.pi-desktop.pages.dev

View logs

@vastsa
vastsa merged commit 86bedd0 into main Nov 21, 2026
7 checks passed
@vastsa
vastsa deleted the feat/codemode-sandbox branch November 21, 2026 14:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature] 支持 Codemode:在独立沙盒里用脚本批量调工具、MCP 和辅助模型

1 participant