Codemode is a lightweight scripting layer added to Pi that lets an LLM orchestrate complex, harness-side operations in a sandboxed language runtime instead of stuffing everything into tool calls or the model context. It treats the harness as the "brain" and the execution environment as the "hands," acknowledging the trust and filesystem boundary between them. Because some capabilities (for example reading images, spawning subagents, or calling internal model APIs) cannot be expressed well as simple CLI tools, Codemode runs JavaScript in a QuickJS/WASM sandbox with strict limits (no network, no host filesystem access, no timers, limited RAM). That environment issues structured tool calls, supports concurrency and basic workflows, and can persist transient state into the session transcript so subsequent Codemode invocations can load it.
Practically, Codemode lets agents call internal AI SDK features that would otherwise waste or overflow context: generate images and send them back as image content and temporary artifacts; run classifier models like Jev to batch-process GitHub issues and store sentiment results; or orchestrate a 30-step game-debugging loop that queries the engine, classifies state, and issues commands. Pi constrains actual parallel tool runs to four and exposes Codemode when MCP is enabled (or via "defaultTools": "+codemode"). The result is more expressive, structured, and efficient agent workflows without exposing unsafe host capabilities.
Summary generated by AI from the linked article. hn.today is not affiliated with Hacker News or Y Combinator.