<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/what-is-codemode-sldlxw1ny" -->

---
title: What is Codemode | daily.dev
description: Armin Ronacher explains Codemode, a pattern introduced in Pi 1.0 that lets an LLM agent issue and compose tool calls via JavaScript running in a sandboxed...
canonical: https://daily.dev/posts/what-is-codemode-sldlxw1ny
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: What is Codemode | daily.dev
og:description: Armin Ronacher explains Codemode, a pattern introduced in Pi 1.0 that lets an LLM agent issue and compose tool calls via JavaScript running in a sandboxed...
og:url: https://daily.dev/posts/what-is-codemode-sldlxw1ny
og:image: https://api.daily.dev/og/posts/slDLxW1NY.png
og:image:alt: What is Codemode
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# What is Codemode

**[Armin Ronacher](https://daily.dev/sources/mitsuhiko)** · 13 min read · 0 upvotes · 0 comments

## Summary

Armin Ronacher explains Codemode, a pattern introduced in Pi 1.0 that lets an LLM agent issue and compose tool calls via JavaScript running in a sandboxed harness environment (QuickJS in WASM) rather than one-off tool invocations through the model's context. He distinguishes the 'harness' (trusted brain) from the 'execution environment' (the hands running bash), showing how Codemode enables concurrent operations, state persistence across calls via store(), access to internal AI SDK APIs like image generation and classifiers (Jev), and MCP tool discovery and orchestration. He walks through real Pi session examples including image generation, GitHub issue sentiment classification, driving a game engine via a classifier loop, and calling Sentry and Cloudflare MCP servers. He notes current friction points: MCP servers often don't yet target Codemode-aware harnesses, nested Codemode-in-MCP-server patterns (as Cloudflare does) are awkward with double JSON escaping, and durability, binary data handling, and support for smaller models remain unsolved.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://lucumr.pocoo.org/2026/10/6/codemode>

## Questions this post answers

### What is Codemode in the Pi AI harness and how does it work?

Codemode is a feature in Pi 1.0 that lets an LLM agent issue and compose tool calls by writing JavaScript, executed in a sandboxed QuickJS runtime within WASM on the harness side rather than the execution environment. The sandbox has no network, filesystem, or timers access, and can only call further tools, enabling concurrent operations, state persistence via store(), and access to internal AI SDK APIs like image generation and classifiers.

_daily.dev surfaces deep dives like this for engineers designing agent harnesses and tool orchestration._

### Why can't bash alone handle everything an LLM agent needs to do?

Bash can only compose programs that run, but some operations are native to the LLM and not expressible as CLI programs, such as reading an image (which requires injecting image payload directly into the model's protocol) or spawning and orchestrating sub-agents, which would require crude workarounds like environment variables and Unix sockets to talk to the outer harness.

_Developers weighing CLI-based versus native tool approaches for agents can track this reasoning on daily.dev._

### What problems arise when an MCP server implements its own code-execution mode, like Cloudflare's code mode?

Running Codemode inside an MCP server creates 'Codemode in Codemode,' which requires double JSON escaping, confuses smaller models, and prevents the inner code from calling the outer harness's tools. For example, using the Cloudflare MCP server in Pi forces the agent to write JavaScript that gets funneled through another layer of JavaScript, which is not optimal.

_Anyone integrating MCP servers into agent harnesses can follow these tradeoffs via daily.dev._

## Similar posts on daily.dev

- [How Code Mode Builds on MCP for Agent Tooling](https://daily.dev/posts/how-code-mode-builds-on-mcp-for-agent-tooling-bjty4eiot) · Nordic APIs · 1 upvotes · 0 comments
- [Cloudflare Launches Code Mode MCP Server to Optimize Token Usage for AI Agents](https://daily.dev/posts/cloudflare-launches-code-mode-mcp-server-to-optimize-token-usage-for-ai-agents-zsfuoyvqc) · InfoQ · 2 upvotes · 0 comments
- [MCP on Code Mode with Matt Carey, Cloudflare Agents SDK and MCP \(Changelog Interviews \#681\)](https://daily.dev/posts/mcp-on-code-mode-with-matt-carey-cloudflare-agents-sdk-and-mcp-changelog-interviews-681--xbm64jsql) · Changelog · 0 upvotes · 0 comments
- [OpenCode Code Mode explained: JavaScript instead of repeated tool calls](https://daily.dev/posts/opencode-code-mode-explained-javascript-instead-of-repeated-tool-calls-fx41rfmf4) · Flavio Copes · 0 upvotes · 0 comments

---

Tags: [#javascript](https://daily.dev/tags/javascript), [#ai-agents](https://daily.dev/tags/ai-agents), [#mcp](https://daily.dev/tags/mcp)

[View this post on daily.dev](https://daily.dev/posts/what-is-codemode-sldlxw1ny)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"TechArticle","headline":"What is Codemode","url":"https://daily.dev/posts/what-is-codemode-sldlxw1ny","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/what-is-codemode-sldlxw1ny"},"datePublished":"2026-10-06T13:33:00.597Z","dateModified":"2026-10-06T13:35:28.892Z","description":"Armin Ronacher explains Codemode, a pattern introduced in Pi 1.0 that lets an LLM agent issue and compose tool calls via JavaScript running in a sandboxed...","image":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/e3cfbe4e6809e6e830242f8833c1e678?_a=AQAEuop","thumbnailUrl":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/e3cfbe4e6809e6e830242f8833c1e678?_a=AQAEuop","isAccessibleForFree":true,"articleSection":"Armin Ronacher","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Organization","name":"Armin Ronacher","logo":"https://media.daily.dev/image/upload/t_logo,f_auto/v1/logos/a7ee3aca0fbd455ea7510f79c0dd61fe","url":"https://daily.dev/sources/mitsuhiko"},"commentCount":0,"discussionUrl":"https://daily.dev/posts/what-is-codemode-sldlxw1ny","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":0},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":0}],"keywords":"javascript,ai-agents,mcp","timeRequired":"PT13M"}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"Armin Ronacher","item":"https://daily.dev/sources/mitsuhiko"},{"@type":"ListItem","position":3,"name":"What is Codemode"}]}
{"@context":"https://schema.org","@type":"FAQPage","@id":"https://daily.dev/posts/what-is-codemode-sldlxw1ny#faq","mainEntity":[{"@type":"Question","name":"What is Codemode in the Pi AI harness and how does it work?","acceptedAnswer":{"@type":"Answer","text":"Codemode is a feature in Pi 1.0 that lets an LLM agent issue and compose tool calls by writing JavaScript, executed in a sandboxed QuickJS runtime within WASM on the harness side rather than the execution environment. The sandbox has no network, filesystem, or timers access, and can only call further tools, enabling concurrent operations, state persistence via store(), and access to internal AI SDK APIs like image generation and classifiers. daily.dev surfaces deep dives like this for engineers designing agent harnesses and tool orchestration."}},{"@type":"Question","name":"Why can't bash alone handle everything an LLM agent needs to do?","acceptedAnswer":{"@type":"Answer","text":"Bash can only compose programs that run, but some operations are native to the LLM and not expressible as CLI programs, such as reading an image (which requires injecting image payload directly into the model's protocol) or spawning and orchestrating sub-agents, which would require crude workarounds like environment variables and Unix sockets to talk to the outer harness. Developers weighing CLI-based versus native tool approaches for agents can track this reasoning on daily.dev."}},{"@type":"Question","name":"What problems arise when an MCP server implements its own code-execution mode, like Cloudflare's code mode?","acceptedAnswer":{"@type":"Answer","text":"Running Codemode inside an MCP server creates 'Codemode in Codemode,' which requires double JSON escaping, confuses smaller models, and prevents the inner code from calling the outer harness's tools. For example, using the Cloudflare MCP server in Pi forces the agent to write JavaScript that gets funneled through another layer of JavaScript, which is not optimal. Anyone integrating MCP servers into agent harnesses can follow these tradeoffs via daily.dev."}}]}
```

