> ## Documentation Index
> Fetch the complete documentation index at: https://axe-engine.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Architecture

> How callers, the sandbox boundary, the axed daemon and the axe engine fit together.

![Callers outside the sandbox (Agent Sandbox SDKs, Agent Substrate, AI agents over MCP, your platform) reach axed over gRPC, REST and MCP. Inside the sandbox, axed holds the native API, the Agent Sandbox adapter, the Agent Substrate adapter and the MCP adapter on top of TCP, vsock, Unix socket and inherited fd transports. Below it the axe engine provides processes, the output log, lifecycle, confined files, the watcher, cgroups v2, budgets and timeouts, on the Linux kernel. The sandbox is isolated by a container, gVisor or Firecracker.](https://mintcdn.com/axe-engine/FTNuG-7AbXB_WZEM/assets/architecture-light.png?fit=max\&auto=format\&n=FTNuG-7AbXB_WZEM\&q=85\&s=90df895c3db6874185b371a01701f83d)

## Callers

Callers live outside the sandbox. They are whatever needs to run commands or move files inside it:

* The Kubernetes Agent Sandbox SDKs for Go, Python and TypeScript, unchanged.
* Agent Substrate's control plane and guest clients.
* AI agents that call axed's MCP tools directly.
* Your own platform: an orchestrator, a CI system, a host agent, or `axectl`.

## The isolation boundary

The sandbox platform draws the boundary: a container, gVisor or a Firecracker microVM. AXE runs inside it and does not provide isolation itself. It assumes the code it runs is hostile and protects itself and the workspace from that code, but it is not what keeps that code away from the host. See [Security](https://axe-engine.mintlify.site/deploy/security.md).

## axed, the daemon

`axed` is a single static binary, usually the sandbox's first process (PID 1). It has three layers.

**Transports.** axed accepts connections on any number of `--listen` endpoints at once: TCP for containers and gVisor, vsock for microVMs without guest networking, a Unix socket for a host supervisor or a bind-mounted socket, and an inherited descriptor (`fd://N`) for socket activation. Every listener serves the same gRPC services and has its own auth policy. axed serves the Agent Sandbox REST API separately, on `--rest-port`, and MCP on its own `--mcp-listen` endpoints, which take the same URIs.

**The native API.** `axe.v1` has three services: `Processes`, `Files` and `System`. It is self-contained and imports no other project's types. See the [native API reference](https://axe-engine.mintlify.site/reference/native-api.md).

**Adapters.** Adapters translate other projects' protocols onto the engine:

* The Kubernetes Agent Sandbox adapter serves sandboxd's `process.v1` and `watcher.v1` gRPC services and its REST file API. It is on by default, and `--agent-sandbox=false` turns it off.
* The Agent Substrate adapter serves `ateenv.v1alpha`, the guest API of `ate-env-guest`. It is off by default, and `--agent-substrate` turns it on.
* The MCP adapter serves the Model Context Protocol's tools to agents, over HTTP at `/mcp`. It is off by default, and each `--mcp-listen` endpoint turns it on there. See [Agents over MCP](https://axe-engine.mintlify.site/deploy/mcp.md).

An adapter maps wire formats and error codes. Behavior lives in the engine, so every API sees the same processes, retention and limits.

## The axe engine

`crates/axe` is a Rust library with no network or protocol code. You can link it into your own agent instead of running axed. See [Embed in Rust](https://axe-engine.mintlify.site/embed/rust.md).

| Part | What it does |
| - | - |
| Supervisor | Spawns processes with argv, environment, working directory, user, an optional PTY and limits. Ids are 128 random bits and never reused. |
| Output log | One log per process holding stdout and stderr in write order. Every byte has an absolute offset, so a client can resume from any point while the bytes are retained. |
| Reaper | One dedicated thread collects every child with `wait4`. As PID 1 it reaps orphans; otherwise it registers as a child subreaper. |
| Lifecycle | Samples three clocks every second to detect suspend and restore where the clocks show the gap, records restores the platform reports, counts resumes as a `generation`, and makes timeouts count running time only. |
| Confined filesystem | Resolves each path one component at a time against held directory descriptors, so a symlink swap cannot escape the root. A new or replaced file stays invisible until its upload commits. |
| Watcher | Streams inotify changes under a directory, and reports a queue overflow so a client knows to rescan. |
| cgroups | With a delegated cgroup v2 subtree, gives each process its own cgroup for whole-tree kill, memory, CPU and task limits, OOM detection and freezing. Falls back to process groups and rlimits. |
| Budgets | Caps retained output across all processes (`--output-budget`), output buffered by unary executions (`--capture-budget`), the number of tracked processes, client connections and concurrent watches. |

## The path of a request

Take `axectl run -- make` against a daemon listening on TCP:

1. The client opens an HTTP/2 connection to a listener. axed counts it against that listener's share of the connection cap, and closes it if the HTTP/2 handshake does not arrive within 10 seconds.
2. The listener's interceptor checks the bearer token, if that listener requires one.
3. The native `Processes.Start` handler hands the request to the engine's supervisor.
4. The supervisor reserves the process's output retention from the global budget, creates its cgroup if cgroups are on, and spawns it.
5. Pump tasks read the process's stdout and stderr into its output log. The reaper thread collects its exit status.
6. The client disconnects. The process keeps running, and its output keeps landing in the log.
7. Later, a client calls `Attach` with the offset after the last byte it saw and gets exactly the rest, or a gap event naming the range that was evicted.

A sandboxd client takes the same path through the Agent Sandbox adapter instead of the native handler.

## Key design choices

* **Protocols are adapters over one engine.** No external protocol shapes the engine, so adding or removing an adapter does not change behavior.
* **Output is addressed by byte offset.** A reconnecting client asks for exactly what it missed. A lossless reader applies backpressure; a lossy reader never slows the process.
* **Suspend is detected from the clocks where they show it.** Platforms snapshot without calling into the guest, so AXE watches its clocks. That catches a suspend under gVisor and on VMMs that catch the guest clocks up after a restore. Where the clocks freeze with the guest, as on Firecracker, the platform reports the restore with `System.Configure` (`axectl resumed`). `System.Freeze` quiesces processes before a snapshot on platforms that have a hook for it.
* **One thread owns `wait`.** Nothing else in the process may wait for children, which is also the main rule when you embed the engine.
* **Untrusted code cannot take the daemon down.** axed has no reachable panics, every buffer and table is bounded, and axed marks inherited descriptors close-on-exec.
* **No survival across an axed restart.** When PID 1 exits, the kernel kills the whole PID namespace. Durability means surviving client disconnects and sandbox snapshots.

[Design](https://axe-engine.mintlify.site/design.md) explains each decision and the alternatives that lost.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.