# nanocode

> SDK for frontier embedded agents. Runs Codex and Claude behind one durable runtime, from Rust or from TypeScript through WebAssembly.

Each link opens a page's Markdown. [llms-full.txt](http://nanocode.xyz/llms-full.txt) holds every page in one file.

## Introduction

- [Getting Started](http://nanocode.xyz/docs/introduction/getting-started.md): Install nanocode, then run a first turn from Rust, TypeScript, or the terminal.
- [Why nanocode](http://nanocode.xyz/docs/introduction/why-nanocode.md): One runtime runs Codex, Claude, and Antigravity agents with durable sessions, Code Mode, subagents, and remote hands, natively or in WebAssembly.
- [Concepts](http://nanocode.xyz/docs/introduction/concepts.md): The terms that the nanocode guides and API pages use, each defined once.
- [FAQ](http://nanocode.xyz/docs/introduction/faq.md): Short answers about credentials, models, packaging, storage, and resuming sessions.

## Guides

- [Agents and Turns](http://nanocode.xyz/docs/guides/agents.md): Build a runtime, open an agent session with a provider and model, run turns to their final message, and stop the runtime.
- [Models › Codex](http://nanocode.xyz/docs/models/codex.md): Run OpenAI's GPT models on the Codex harness with a ChatGPT login, an OpenAI API key, or a Responses gateway.
- [Models › Claude](http://nanocode.xyz/docs/models/claude.md): Run Anthropic's Claude models on the Claude harness with a Claude plan login, an Anthropic API key, a custom base URL, or Vertex AI.
- [Models › Google](http://nanocode.xyz/docs/models/google.md): Run Gemini models on the Antigravity harness with a Gemini API key, Vertex AI, or an LLM gateway.
- [Tools](http://nanocode.xyz/docs/guides/tools.md): Offer host functions to the model as tools, from Rust with #[tool] and FunctionTool, or from TypeScript with HostTool definitions and one tools.call function.
- [Events](http://nanocode.xyz/docs/guides/events.md): Read an agent's events while a turn runs, print answer text and tool calls, and read or serve the session's event log.
- [Code Mode](http://nanocode.xyz/docs/guides/code-mode.md): Let the model run JavaScript cells that call registered tools, run calls in parallel, keep values between cells, and return only the output it needs.
- [Subagents](http://nanocode.xyz/docs/guides/subagents.md): Let an agent spawn child agents with their own model, effort, and typed output contract, and stream updates from the whole agent tree.
- [Durability](http://nanocode.xyz/docs/guides/durability.md): Journal every turn to a store, reopen a session by ID after a restart, and retry a prompt by request ID without repeating its side effects.
- [Remote Hands](http://nanocode.xyz/docs/guides/remote-hands.md): Keep inference, subagents, and durability in one brain process, and run Code Mode cells and tools on hands such as laptops, build machines, or sandboxes.
- [Model Gateways](http://nanocode.xyz/docs/guides/gateways.md): Send Codex models through OpenRouter, Vercel AI Gateway, or Cloudflare AI Gateway, with the agent code unchanged.
- [MPP Payments](http://nanocode.xyz/docs/guides/mpp-payments.md): Pay for each model and MCP request through hooks that the SDK and the nanocode CLI expose, as nanocode-machines does with Machine Payments Protocol (MPP) sessions.
- [xframes](http://nanocode.xyz/docs/guides/xframes.md): xframes is a Cloudflare Worker where mentioning @nanocodexyz on X makes a nanocode agent build an app that runs inside the reply.
- [Deploy › In the Browser](http://nanocode.xyz/docs/guides/browser.md): Run a nanocode session in a web page, with sqlite-wasm for storage and a server-side proxy that holds the model credentials.
- [Deploy › Cloudflare Workers](http://nanocode.xyz/docs/guides/workers.md): Run nanocode sessions in Durable Objects: import the module through Wrangler, store each session in Durable Object SQL, and stream events over Server-Sent Events.
- [Deploy › Vercel Functions](http://nanocode.xyz/docs/guides/vercel.md): Run a durable nanocode agent in Vercel Functions, with its journal kept as steps of a Workflow run, so a turn finishes after the Function that started it dies.
- [Deploy › nanocode-ts](http://nanocode.xyz/docs/guides/nanocode-ts.md): nanocodexyz/nanocode-ts compiles the nanocode Rust SDK into one WebAssembly module and runs it from TypeScript, with adapters for Vercel Functions and Cloudflare Durable Objects.
- [CLI › Terminal UI](http://nanocode.xyz/docs/guides/cli.md): Install nc, sign in to Codex or Claude, and run coding sessions in the terminal.
- [CLI › Headless Runs](http://nanocode.xyz/docs/guides/exec.md): Run one prompt without the terminal interface, for scripts and CI, with nc exec.

## API

- [nanocode › Overview](http://nanocode.xyz/docs/api/rust.md): The Rust SDK facade: one crate that builds a runtime, spawns agents, and runs turns on the Codex and Claude harnesses.
- [nanocode › Nanocode](http://nanocode.xyz/docs/api/rust/Nanocode.md): The runtime that owns the harnesses, tools, durability store, and subagents, and spawns agents that share them.
- [nanocode › SpawnBuilder](http://nanocode.xyz/docs/api/rust/SpawnBuilder.md): Select the harness, model, reasoning, and instructions of a new root agent, then build it.
- [nanocode › Agent](http://nanocode.xyz/docs/api/rust/Agent.md): The handle of one agent session: it runs turns, changes settings, checkpoints, forks, and stops the session.
- [nanocode › Turn](http://nanocode.xyz/docs/api/rust/Turn.md): One running turn of an agent: a future of its result and a stream of its events, with steering and cancellation.
- [nanocode › Tools](http://nanocode.xyz/docs/api/rust/Tools.md): The tool catalog that a runtime gives its agents: built-in tools, registered Rust tools, providers, and how each tool reaches the model.
- [nanocode › #[tool]](http://nanocode.xyz/docs/api/rust/tool-macro.md): An attribute macro that turns an async Rust function into a tool with a typed input and output schema.
- [nanocode › FunctionTool](http://nanocode.xyz/docs/api/rust/FunctionTool.md): A tool defined at runtime by a name, a description, a JSON Schema, and a handler that receives JSON.
- [nanocode › OpenAi](http://nanocode.xyz/docs/api/rust/OpenAi.md): The OpenAI Responses API client that the Codex harness uses for its model requests.
- [nanocode › ClaudeClient](http://nanocode.xyz/docs/api/rust/ClaudeClient.md): The Anthropic Messages API client that the Claude harness uses, and the ClaudeHarness that wraps it.
- [nanocode › ResponsesGateway](http://nanocode.xyz/docs/api/rust/ResponsesGateway.md): A third-party Responses API gateway for the Codex harness: OpenRouter, Vercel AI Gateway, or Cloudflare.
- [nanocode › session_store](http://nanocode.xyz/docs/api/rust/session_store.md): Wrap a state store in a SessionStore that journals sessions, turns, and tool receipts for both built-in harnesses.
- [nanocode › hand](http://nanocode.xyz/docs/api/rust/hand.md): Run Code Mode cells and tools on another machine, a hand, for a runtime that keeps inference and durability.
- [nanocode › Models and Types](http://nanocode.xyz/docs/api/rust/types.md): The model, reasoning, service tier, error, checkpoint, and usage types that the nanocode crate re-exports.
- [nanocode-ts › Overview](http://nanocode.xyz/docs/api/wasm.md): The nanocode SDK compiled to one WebAssembly module, with a TypeScript host for Workers, Node, Deno, and browsers.
- [nanocode-ts › AgentRuntime](http://nanocode.xyz/docs/api/wasm/AgentRuntime.md): The runtime that runs the nanocode WebAssembly module for one session scope. AgentRuntime.instantiate returns it, and its type is AgentRuntime.AgentRuntime.
- [nanocode-ts › instantiate](http://nanocode.xyz/docs/api/wasm/instantiate.md): Instantiate the nanocode WebAssembly module for one session scope.
- [nanocode-ts › open](http://nanocode.xyz/docs/api/wasm/open.md): Open the SDK session on an instantiated runtime.
- [nanocode-ts › submit](http://nanocode.xyz/docs/api/wasm/submit.md): Queue a turn in the session log.
- [nanocode-ts › drive](http://nanocode.xyz/docs/api/wasm/drive.md): Run one root turn through the SDK's turn inbox.
- [nanocode-ts › turn and pending](http://nanocode.xyz/docs/api/wasm/turn.md): Read one turn of the session log, or the turns that still need to run.
- [nanocode-ts › page](http://nanocode.xyz/docs/api/wasm/page.md): Read logged events after a cursor.
- [nanocode-ts › cancel](http://nanocode.xyz/docs/api/wasm/cancel.md): Cancel a queued or running turn.
- [nanocode-ts › dispose](http://nanocode.xyz/docs/api/wasm/dispose.md): Shut the SDK session down and release the runtime's host resources.
- [nanocode-ts › SqlHost](http://nanocode.xyz/docs/api/wasm/SqlHost.md): The interface that runs the SDK's SQL statements in atomic SQLite transactions.
- [nanocode-ts › HostTool](http://nanocode.xyz/docs/api/wasm/HostTool.md): A tool that the host defines and runs, offered to the model with a JSON Schema.
- [nanocode-ts › EventHub](http://nanocode.xyz/docs/api/wasm/EventHub.md): A bounded tail of recent events that wakes waiters and serves Server-Sent Events.
- [nanocode-ts › Remote](http://nanocode.xyz/docs/api/wasm/RemoteExecutor.md): Carry the SDK's remote Code Mode frames over a message socket.
- [nanocode-ts › Contracts.sessionUuid](http://nanocode.xyz/docs/api/wasm/sessionUuid.md): Make a UUIDv7 session ID for config.session_id.
- [nanocode-ts › Contracts.HostFailureError](http://nanocode.xyz/docs/api/wasm/HostFailure.md): An error with a failure kind and a flag that tells the host whether a retry can succeed.
- [nanocode-ts › Types](http://nanocode.xyz/docs/api/wasm/types.md): The exported types and constants of nanocode-ts that no other page covers.
- [CLI](http://nanocode.xyz/docs/api/cli.md): Reference for the nanocode binary and its nc alias: every subcommand, option, and environment variable.

## Experiments

- [Nanocode: The Harness for Swarms](http://nanocode.xyz/experiments/the-harness-for-swarms.md): nanocode is an agent harness built for swarms. One process runs a terminal agent in a few milliseconds and a tree of a million scripted subagents in under an hour. We measured both against five other coding agents and against itself, and dated every number.
- [The Harness Outside the Sandbox](http://nanocode.xyz/experiments/harness-outside-the-sandbox.md): Agents do not need a computer to think. nanocode runs the agent loop and its session in a process the host already has, such as a Worker, a Function, or a browser tab, and attaches a machine only for the calls that need one.
- [Durable Nanocode](http://nanocode.xyz/experiments/durable-nanocode.md): Processes die, and agents should not die with them. nanocode journals every turn, model call, and tool call to storage the host already has. A turn finishes after its process dies, and a call that was running then is reported as uncertain, not silently retried.
- [One SDK, Every Language](http://nanocode.xyz/experiments/one-sdk-every-language.md): Write the agent once in Rust and run it everywhere. nanocode is one Rust SDK, and TypeScript, Swift, Python, and C do not reimplement it: each is a thin layer over the same compiled code.
- [Code Mode Is Necessary](http://nanocode.xyz/experiments/code-mode-is-necessary.md): Agents should write programs, not click through tools one call at a time. In Code Mode the model writes a cell that calls the tools, and only what the cell returns enters its context.
- [Making Every Machine Feel as One](http://nanocode.xyz/experiments/hands.md): An agent should use every machine it can reach as if it were one computer. A nanocode brain keeps the model loop, the journal, and subagents in one process, and hands run its code on a laptop, a build server, or a browser tab.
- [Embedded Bash, JavaScript and Python](http://nanocode.xyz/experiments/embedded-bash-javascript-python.md): An agent should not need a container just to compose tools, search files, or draw a chart. nanocode connects three embedded runtimes: djs for JavaScript cells, psh for Bash-style commands, and RustPython for Python programs.
- [djs in Code Mode](http://nanocode.xyz/experiments/djs.md): nanocode embeds a modified djs JavaScript engine for Code Mode, where model-written programs call tools and process their results. This page separates upstream work, local changes, and historical measurements.
- [psh in Process](http://nanocode.xyz/experiments/psh.md): nanocode embeds a modified psh shell to run agent commands and common utilities in-process. Standalone shell experiments and the shell shipped in the TypeScript SDK are different artifacts.
- [RustPython Package Coverage](http://nanocode.xyz/experiments/python.md): nanocode-python embeds a modified RustPython interpreter, not CPython. This experiment measures installation and small execution probes for a fixed package matrix, not general Python compatibility.
- [Durable Nanocode on Cloudflare](http://nanocode.xyz/experiments/durable-nanocode-on-cloudflare.md): Each session is one Durable Object, and the object's own SQLite is the agent's journal. A deploy or an eviction resets the object mid-turn, and the next instance finishes the turn from what the journal holds.
- [Durable Nanocode on Vercel](http://nanocode.xyz/experiments/durable-nanocode-on-vercel.md): A Vercel Function has no database and no long life. So each session's Workflow run is the journal: every SQL batch nanocode commits is a step of the run, and the next Function replays the steps and finishes the turn.
