# 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](https://nanocode.xyz/llms-full.txt) holds every page in one file.

## Introduction

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

## Guides

- [Agents and Turns](https://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.
- [Tools](https://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](https://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](https://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](https://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](https://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](https://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](https://nanocode.xyz/docs/guides/gateways.md): Send Codex models through OpenRouter, Vercel AI Gateway, or Cloudflare AI Gateway, with the agent code unchanged.
- [Deploy › In the Browser](https://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](https://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.
- [CLI › Terminal UI](https://nanocode.xyz/docs/guides/cli.md): Install nc, sign in to Codex or Claude, and run coding sessions in the terminal.
- [CLI › Headless Runs](https://nanocode.xyz/docs/guides/exec.md): Run one prompt without the terminal interface, for scripts and CI, with nc exec.
- [Experiments › xframes](https://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.
- [Experiments › MPP Payments](https://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.
- [Experiments › nanocode-ts](https://nanocode.xyz/docs/guides/nanocode-ts.md): gakonst/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.

## API

- [nanocode › Overview](https://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](https://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](https://nanocode.xyz/docs/api/rust/SpawnBuilder.md): Select the harness, model, reasoning, and instructions of a new root agent, then build it.
- [nanocode › Agent](https://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](https://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](https://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]](https://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](https://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](https://nanocode.xyz/docs/api/rust/OpenAi.md): The OpenAI Responses API client that the Codex harness uses for its model requests.
- [nanocode › ClaudeClient](https://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](https://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](https://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](https://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](https://nanocode.xyz/docs/api/rust/types.md): The model, reasoning, service tier, error, checkpoint, and usage types that the nanocode crate re-exports.
- [nanocode-wasm › Overview](https://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-wasm › AgentRuntime](https://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-wasm › instantiate](https://nanocode.xyz/docs/api/wasm/instantiate.md): Instantiate the nanocode WebAssembly module for one session scope.
- [nanocode-wasm › open](https://nanocode.xyz/docs/api/wasm/open.md): Open the SDK session on an instantiated runtime.
- [nanocode-wasm › submit](https://nanocode.xyz/docs/api/wasm/submit.md): Queue a turn in the session log.
- [nanocode-wasm › drive](https://nanocode.xyz/docs/api/wasm/drive.md): Run one root turn through the SDK's turn inbox.
- [nanocode-wasm › turn and pending](https://nanocode.xyz/docs/api/wasm/turn.md): Read one turn of the session log, or the turns that still need to run.
- [nanocode-wasm › page](https://nanocode.xyz/docs/api/wasm/page.md): Read logged events after a cursor.
- [nanocode-wasm › cancel](https://nanocode.xyz/docs/api/wasm/cancel.md): Cancel a queued or running turn.
- [nanocode-wasm › dispose](https://nanocode.xyz/docs/api/wasm/dispose.md): Shut the SDK session down and release the runtime's host resources.
- [nanocode-wasm › SqlHost](https://nanocode.xyz/docs/api/wasm/SqlHost.md): The interface that runs the SDK's SQL statements in atomic SQLite transactions.
- [nanocode-wasm › HostTool](https://nanocode.xyz/docs/api/wasm/HostTool.md): A tool that the host defines and runs, offered to the model with a JSON Schema.
- [nanocode-wasm › EventHub](https://nanocode.xyz/docs/api/wasm/EventHub.md): A bounded tail of recent events that wakes waiters and serves Server-Sent Events.
- [nanocode-wasm › Remote](https://nanocode.xyz/docs/api/wasm/RemoteExecutor.md): Carry the SDK's remote Code Mode frames over a message socket.
- [nanocode-wasm › Contracts.sessionUuid](https://nanocode.xyz/docs/api/wasm/sessionUuid.md): Make a UUIDv7 session ID for config.session_id.
- [nanocode-wasm › Contracts.HostFailureError](https://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-wasm › Types](https://nanocode.xyz/docs/api/wasm/types.md): The exported types and constants of nanocode-wasm that no other page covers.
- [CLI](https://nanocode.xyz/docs/api/cli.md): Reference for the nanocode binary and its nc alias: every subcommand, option, and environment variable.
