> ## 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.

# Native API (axe.v1)

> AXE's own gRPC API: the Processes, Files and System services, every RPC and field, streaming behavior, offsets and errors.

`axe.v1` is the gRPC API axed serves on every `--listen` endpoint. The source of truth is [`proto/axe/v1/axe.proto`](https://github.com/vincent0426/axe/blob/main/proto/axe/v1/axe.proto).

## Connecting

* **Endpoints.** Every listener serves `axe.v1`: TCP, Unix socket, vsock or an inherited descriptor. See [`--listen`](https://axe-engine.mintlify.site/reference/axed#listeners-and-auth).
* **Auth.** With a token configured, send it as `authorization: Bearer <token>` or `x-sandboxd-token: <token>` metadata on every call. A missing or wrong token fails with `UNAUTHENTICATED` (`missing or invalid bearer token`). Listeners with `?auth=none` skip the check.
* **Reflection.** axed serves `grpc.reflection.v1`. It lists only the services enabled on the daemon: `axe.v1` and whichever adapters are on. `grpcurl` and similar tools need no proto files. Reflection needs the token like every other service, except on `?auth=none` listeners.
* **Keepalive.** The server pings every 20 seconds and drops a connection that does not answer within 10 seconds. A new connection must send the HTTP/2 preface and first frame within 10 seconds.
* **Errors.** Engine errors map to gRPC codes as listed in [Errors](https://axe-engine.mintlify.site/reference/errors.md). The errors a client branches on also carry a `google.rpc.ErrorInfo` with a machine-readable reason, such as `NAME_IN_USE`. See [Reasons](https://axe-engine.mintlify.site/reference/errors.md#reasons).
* **Health.** axed serves `grpc.health.v1` on every gRPC listener, without the token. The overall status (service `""`) is `SERVING` until shutdown starts, then `NOT_SERVING`. Kubernetes gRPC probes can use it.

```sh theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
grpcurl -plaintext -H "authorization: Bearer $TOKEN" localhost:9090 list
grpcurl -plaintext -H "authorization: Bearer $TOKEN" \
  -d '{"spec": {"command": ["uname", "-a"]}}' localhost:9090 axe.v1.Processes/Exec
```

## Concepts

**Process ids** are opaque 32-hex-digit strings. They are never reused and belong to one daemon instance. After a cold boot the instance id changes and old ids are unknown.

**Output** from stdout and stderr goes into one log per process, addressed by byte offset. Offsets start at 0 and never reset, so replay keeps stdout and stderr interleaved. The log keeps the most recent `retain_bytes`. `Process.output_start` is the oldest retained offset and `output_end` is one past the newest.

**Readers** are lossless by default. When a reader has not read output and keeping it would exceed retention, axed holds the process back until the reader reads. A lossy reader never slows the process and gets `Gap` events for evicted bytes.

**Lifetime.** axed keeps processes from `Start`, `Run`, `Exec` with a `request_id`, and the Agent Substrate API after exit for reattach, until they are removed, until `--max-finished` newer ones have finished, or until the output budget needs the space. axed forgets processes from `Exec` without a `request_id` when they exit.

**Retries.** `Start`, `Run` and `Exec` take a `request_id`. Repeating a request with the same id and the same request returns the first one's process (or, for `Exec`, its result) instead of running the command again. The same id with a different request fails with `ALREADY_EXISTS` (`REQUEST_ID_CONFLICT`). Once axed has evicted the process, a repeat fails with `FAILED_PRECONDITION` (`REQUEST_EXPIRED`), for as long as axed remembers the id: it remembers the last 4096 evicted ids. A process removed with `Remove` frees its id for a new request.

**Paths** in `Files` are relative to the daemon's root. Absolute paths under the root are accepted; absolute paths outside it fail with `PERMISSION_DENIED`, as does any path that climbs above the root with `..`. Resolution never leaves the root, even through symlinks. See [File confinement](https://axe-engine.mintlify.site/files/confinement.md).

## Processes

### Common messages

#### ProcessRef

Names a process. Exactly one of:

| Field | Type | Meaning |
| - | - | - |
| `id` | string | The process id. |
| `name` | string | The running process with this name, or if none is running, the most recently finished process with this name that the daemon still keeps. |

And optionally:

| Field | Type | Meaning |
| - | - | - |
| `instance_id` | string | The `instance_id` the client learned the process under. When set and the daemon's differs, because it cold-booted, the call fails with `NOT_FOUND` and reason `INSTANCE_CHANGED`, so the client knows the process is gone for good rather than mistyped. |

An unknown id or name fails with `NOT_FOUND`. A `ProcessRef` with neither field fails with `INVALID_ARGUMENT`.

#### Spec

What to run.

| Field | Type | Meaning |
| - | - | - |
| `command` | repeated string | Program and arguments. Required; empty fails with `INVALID_ARGUMENT`. axed looks up the program on `PATH`. |
| `env` | map | Added to the daemon's environment. |
| `cwd` | string | Working directory inside the root. Empty means the root. Relative paths and absolute paths under the root are accepted; an absolute path outside the root, or a path that climbs above it, fails with `PERMISSION_DENIED`, as in `Files`. Missing: `NOT_FOUND`. Not a directory: `INVALID_ARGUMENT`. |
| `terminal` | Terminal | Run on a pseudo-terminal of `cols` by `rows` instead of pipes. A zero `cols` or `rows` keeps the kernel's default size. axed reports output as stdout and sets `TERM` to `xterm-256color` unless `env` or the daemon's environment sets it. |
| `stdin` | bool | Keep stdin open for `WriteInput`. Without it stdin is `/dev/null`. Terminals always have input. |
| `limits` | Limits | Resource limits. |
| `user` | string | A name from `/etc/passwd`, a uid, or `uid:gid`. A uid not in `/etc/passwd` runs with gid equal to the uid. An unknown name fails with `NOT_FOUND`. A `uid:gid` form that is not two numbers, such as `a:b`, fails with `INVALID_ARGUMENT`. Empty runs as `--default-user`, or as the daemon's user without it. |

A program that does not exist fails with `NOT_FOUND`; one that cannot be executed fails with `PERMISSION_DENIED`.

#### Limits

Every set value must be positive; `0` fails with `INVALID_ARGUMENT`. A limit the request leaves unset takes the daemon's default (`--default-timeout`, `--default-memory`, `--default-max-tasks`) or else its ceiling (`--max-timeout`, `--max-memory`). A `timeout` or `memory_bytes` above its ceiling fails with `INVALID_ARGUMENT` (`LIMIT_EXCEEDED`), naming the flag. All of them are off by default. `Info` reports them.

| Field | Type | Meaning |
| - | - | - |
| `memory_bytes` | optional uint64 | Hard memory ceiling. cgroup `memory.max` for the tree when the daemon manages cgroups, otherwise `RLIMIT_AS` per process. |
| `cpu_millis` | optional uint32 | CPU bandwidth in millicores, 1000 for one CPU. Requires cgroups; without them the start fails with `FAILED_PRECONDITION`. |
| `max_tasks` | optional uint32 | Most tasks in the tree: cgroup `pids.max`, otherwise `RLIMIT_NPROC`. |
| `open_files` | optional uint64 | `RLIMIT_NOFILE` per process. |
| `timeout` | Duration | Kill the tree with `SIGKILL` after this much running time. Time the sandbox spends suspended does not count. The exit reports `EXIT_REASON_TIMED_OUT`. |

#### Process

| Field | Type | Meaning |
| - | - | - |
| `id` | string | Process id. |
| `name` | string | Name, or empty. |
| `pid` | int32 | Host pid of the leader, `0` once it has been reaped. |
| `command` | repeated string | The command. |
| `labels` | map | Labels from the start request. |
| `state` | State | `STATE_RUNNING` or `STATE_EXITED`. |
| `terminal` | bool | Runs on a pseudo-terminal. |
| `started_at` | Timestamp | When it started. |
| `exited_at` | Timestamp | When it exited. Unset while running. |
| `exit` | Exit | How it ended. Unset while running. |
| `usage` | Usage | Resource use, read when the process is described: what it uses now while it runs, its totals once it has exited. Unset if nothing could be read. |
| `output_start` | uint64 | Offset of the oldest retained output byte. |
| `output_end` | uint64 | Offset one past the newest output byte. |
| `stdin_offset` | uint64 | Stdin bytes accepted so far. |
| `instance_id` | string | The daemon instance this id belongs to. |

#### Exit

| Field | Type | Meaning |
| - | - | - |
| `exit_code` | int32 | The exit status, or 128 plus the signal number. |
| `signal` | optional int32 | The signal that killed the leader, if any. |
| `reason` | ExitReason | Why it ended. |

`ExitReason` is one of these. When axed killed the tree, the first cause it acted on wins, whatever status that left. A process that axed asked to stop but that exited first keeps `EXITED` or `SIGNALED`.

| Value | Meaning |
| - | - |
| `EXIT_REASON_EXITED` | The leader exited on its own. |
| `EXIT_REASON_SIGNALED` | A signal ended the leader. Signals sent with `Signal` count here: axed only delivers them. |
| `EXIT_REASON_TIMED_OUT` | `Limits.timeout` ran out. |
| `EXIT_REASON_OOM_KILLED` | The kernel killed the tree for exceeding `memory_bytes`. Seen only with cgroups. |
| `EXIT_REASON_KILLED` | A client killed it with `Remove` and `kill`. |
| `EXIT_REASON_OWNER_GONE` | The call that owned it ended: `Run` without `detach`, or `Exec` without a `request_id`. |
| `EXIT_REASON_SHUTDOWN` | axed stopped it while shutting down. |
| `EXIT_REASON_UNKNOWN` | axed reaped the leader but lost its exit status; `exit_code` is -1. |

#### Usage

| Field | Type | Meaning |
| - | - | - |
| `user_cpu`, `system_cpu` | Duration | CPU time so far, or in total after exit. |
| `peak_memory_bytes` | uint64 | The cgroup's `memory.peak`, or after exit without a cgroup, the leader's peak resident set. `0` when unknown, as for a running process without a cgroup. |
| `memory_bytes` | uint64 | Running only: memory in use now, the cgroup's `memory.current` or the leader's resident set. |
| `tasks` | uint32 | Running only: tasks now, the cgroup's `pids.current` (or the threads it lists) or the leader's threads. |
| `scope` | UsageScope | `USAGE_SCOPE_TREE`: the figures cover the whole tree, from its cgroup. `USAGE_SCOPE_LEADER`: only the leader, from `/proc` while it runs and from `wait4` at exit, for a process without a cgroup. |

axed reads usage only when a process is described, by `Get`, `List`, `Wait` and the events that carry a `Process`. It never samples in the background. Without the memory controller, the memory figures of a tree read `0`.

#### ProcessEvent

A streamed event. Exactly one of:

| Field | Type | Meaning |
| - | - | - |
| `started` | Process | Always the first event. Describes the process. |
| `output` | Output | `offset`, `stream` (`OUTPUT_STREAM_STDOUT` or `OUTPUT_STREAM_STDERR`) and `data`. Chunks are at most `--stream-chunk-size` bytes. Do not depend on chunk boundaries. |
| `gap` | Gap | Bytes in `[from_offset, to_offset)` were evicted before this reader saw them. |
| `exited` | Process | The process after it exited, with `exit` and `usage`. The last event when present. |

### Start

```proto theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
rpc Start(StartRequest) returns (Process);
```

Launches a detached process and returns once it is running. The process keeps running whether or not anyone reads it.

| Field | Type | Meaning |
| - | - | - |
| `spec` | Spec | What to run. |
| `name` | string | Unique among running processes. A name in use fails with `ALREADY_EXISTS` (`NAME_IN_USE`). The name frees when the process exits. |
| `request_id` | string | Idempotency key. Repeating the same start returns the process the first one created. A start that differs in `spec`, `name`, `labels` or `retain_bytes` fails with `ALREADY_EXISTS` (`REQUEST_ID_CONFLICT`). See [Retries](#concepts). |
| `labels` | map | Free-form labels, for `List`. |
| `retain_bytes` | uint64 | Output retained for replay. `0` selects `--retain`. More than `--max-retain` fails with `INVALID_ARGUMENT` (`LIMIT_EXCEEDED`). |

Fails with `RESOURCE_EXHAUSTED` (`BUDGET_EXHAUSTED`) when running processes hold the whole output budget or the process table is full, with `FAILED_PRECONDITION` (`FROZEN`) while processes are frozen, and with `FAILED_PRECONDITION` while the daemon shuts down.

### Run

```proto theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
rpc Run(RunRequest) returns (stream ProcessEvent);
```

Starts a process and streams its events in one call: `started`, then `output`, then `exited`. The reader is lossless, so a new process never produces `gap`.

| Field | Type | Meaning |
| - | - | - |
| `start` | StartRequest | As for `Start`. |
| `detach` | bool | Keep the process running if the stream ends before it exits. Without it, axed kills the process tree when the client cancels or disconnects. |

axed keeps the process after exit like one from `Start`. A slow client holds the process back once retention is full.

Repeating a `request_id` returns the existing process and replays its output from offset 0. If output before the oldest retained byte was already evicted, that stream starts with a `gap`. Without `detach`, the repeated stream also controls the process's lifetime. axed kills the tree if that stream ends before the process exits.

### Exec

```proto theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
rpc Exec(ExecRequest) returns (ExecResponse);
```

Runs a command to completion and returns its output. Without a `request_id`, axed kills the process tree if the call is cancelled, and forgets the process when it exits.

| Field | Type | Meaning |
| - | - | - |
| `spec` | Spec | What to run. |
| `stdout_limit_bytes` | uint64 | Bytes kept from stdout; the rest is read and discarded. `0` or more than 256 MiB selects 256 MiB. |
| `stderr_limit_bytes` | uint64 | The same for stderr. |
| `request_id` | string | Idempotency key, shared with `Start`. With one, the process is kept like a started one, `List` shows it, and it runs to the end even if the call is cancelled. Repeating the same `Exec` returns the first run's result, read from its retained output, without running the command again. Once that output or the process record has been evicted, the repeat fails with `FAILED_PRECONDITION` (`REQUEST_EXPIRED`). |
| `retain_bytes` | uint64 | With a `request_id`: output retained for a repeat, as in `Start`. `0` selects `--retain`. Output beyond it cannot be returned to a repeat. |

A retry after a snapshot, when the first call's connection dropped, is the case `request_id` is for: the first run keeps going and the repeat collects its result.

| Response field | Type | Meaning |
| - | - | - |
| `exit` | Exit | How it ended. |
| `stdout`, `stderr` | bytes | A prefix of each stream. |
| `stdout_truncated`, `stderr_truncated` | bool | Output past the limit was dropped. |
| `elapsed` | Duration | Wall time from start to exit. For a repeated `request_id`, from the first run's start to its exit. |

All concurrent unary executions share a buffer budget, `--capture-budget`. When it is exhausted, further output is dropped and marked truncated instead of waiting.

### Attach

```proto theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
rpc Attach(AttachRequest) returns (stream ProcessEvent);
```

Replays retained output from an offset and then follows the process. The first event is `started`. The last, unless `no_follow` stops early or the stream fails, is `exited`.

| Field | Type | Meaning |
| - | - | - |
| `process` | ProcessRef | The process. |
| `from_offset` | optional uint64 | Replay from this offset. Unset replays everything retained. An offset past the end starts at the end. An offset before `output_start` produces a `gap` first. |
| `lossy` | bool | Never slow the process; get `gap` events instead. By default a slow reader backpressures the process once retention is full. |
| `no_follow` | bool | Stop after replaying what is retained. If the process has already exited, `exited` is still sent; if it is running, the stream ends without it. |

A process allows at most 64 lossless readers at once, counting `Run` streams and lossless `Attach` streams. A lossless `Attach` beyond that fails with `RESOURCE_EXHAUSTED`; lossy readers are not limited.

To resume after a disconnect, pass the offset one past the last byte you received: `offset + len(data)` of the last `output` event.

Attaching to a finished process replays what is retained and ends with `exited`.

### Wait

```proto theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
rpc Wait(WaitRequest) returns (Process);
```

Returns the process (`WaitRequest.process`, a `ProcessRef`) once it has exited and its output is complete. Returns immediately for a finished process.

### Get

```proto theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
rpc Get(GetRequest) returns (Process);
```

Returns the current state of the process `GetRequest.process` names, with its usage now if it is running.

### List

```proto theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
rpc List(ListRequest) returns (ListResponse);
```

Returns every tracked process, running and finished, in start order.

| Field | Type | Meaning |
| - | - | - |
| `labels` | map | Only processes carrying all of these labels with these values. Empty returns all. |

`ListResponse.processes` holds the matches.

### WriteInput

```proto theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
rpc WriteInput(WriteInputRequest) returns (WriteInputResponse);
```

Writes to stdin. The response's `offset` is the total stdin bytes accepted so far.

| Field | Type | Meaning |
| - | - | - |
| `process` | ProcessRef | The process. |
| `data` | bytes | Bytes to write. May be empty. |
| `offset` | optional uint64 | The stdin offset `data` starts at. Makes retries safe. axed acknowledges bytes already accepted without writing them again, and writes only the new tail. An offset past what was accepted fails with `FAILED_PRECONDITION`. Unset appends. |
| `eof` | bool | End input after writing: close stdin, or on a terminal send its end-of-file character (normally Ctrl-D) once, which does not count toward the offset. Ending input again does nothing. |

Fails with `FAILED_PRECONDITION` when the process has no stdin (started without `stdin`), or its stdin was already closed. Writing to a process that has exited fails with `FAILED_PRECONDITION` (`PROCESS_EXITED`). So does a write that is still blocked when the process exits, because the process stopped reading its input. An `offset` that overflows when the length of `data` is added fails with `INVALID_ARGUMENT`. Bytes the process accepted count toward the offset even when the write then fails or is cancelled.

### StreamInput

```proto theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
rpc StreamInput(stream InputChunk) returns (WriteInputResponse);
```

Writes an ordered stream of stdin chunks. For clients that cannot stream, use `WriteInput`.

| Field | Type | Meaning |
| - | - | - |
| `process` | ProcessRef | Required on the first chunk; ignored after. |
| `data` | bytes | Bytes to write. |
| `eof` | bool | End input after this chunk, as `WriteInput` does. |

An empty stream fails with `INVALID_ARGUMENT`. The response's `offset` is the stdin offset after the last chunk.

### Signal

```proto theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
rpc Signal(SignalRequest) returns (SignalResponse);
```

Delivers any signal number to the process group, or to the leader alone.

| Field | Type | Meaning |
| - | - | - |
| `process` | ProcessRef | The process. |
| `signal` | int32 | Signal number. Must be positive; an invalid number fails with `INVALID_ARGUMENT`. |
| `leader_only` | bool | Signal only the leader, through its pidfd when the kernel supports it. By default axed signals the whole process group, or the leader if the group is gone. |

Signaling a process whose leader has exited succeeds and does nothing, even while axed is still collecting its output. A kernel refusal fails with `PERMISSION_DENIED`.

### Resize

```proto theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
rpc Resize(ResizeRequest) returns (ResizeResponse);
```

Sets the terminal size to `cols` by `rows`. axed clamps values above 65535. Fails with `FAILED_PRECONDITION` when the process has no terminal, and with `FAILED_PRECONDITION` (`PROCESS_EXITED`) when it has exited.

### Remove

```proto theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
rpc Remove(RemoveRequest) returns (RemoveResponse);
```

Forgets a finished process and frees its retained output.

| Field | Type | Meaning |
| - | - | - |
| `process` | ProcessRef | The process. |
| `kill` | bool | Kill a running process tree with `SIGKILL`, wait for it to exit, then forget it. The exit reports `EXIT_REASON_KILLED`. Without `kill`, a running process fails with `FAILED_PRECONDITION`. |

A process that is already gone fails with `NOT_FOUND`, as `Get` does. A retried `Remove` that gets `NOT_FOUND` has therefore succeeded.

## Files

### FileInfo

| Field | Type | Meaning |
| - | - | - |
| `name` | string | For `List`, the path relative to the listed directory. For `Stat`, `MakeDir` and `Write`, the last component of the request path, or `/` for the root. |
| `kind` | FileKind | `FILE_KIND_FILE`, `FILE_KIND_DIRECTORY`, or `FILE_KIND_OTHER` for FIFOs, sockets and devices. |
| `size` | uint64 | Size in bytes. |
| `mode` | uint32 | Permission bits. |
| `modified` | Timestamp | Modification time. |

### Stat

```proto theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
rpc Stat(StatRequest) returns (FileInfo);
```

Metadata for `path`, following symlinks. A missing path fails with `NOT_FOUND`.

### List

```proto theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
rpc List(ListDirRequest) returns (stream FileInfo);
```

Streams the entries of a directory in lexical order, each directory before its contents.

| Field | Type | Meaning |
| - | - | - |
| `path` | string | The directory. |
| `depth` | uint32 | `1` lists direct children; `0` means unlimited. |

Symlinks are reported with their target's metadata and never descended into. Broken symlinks and symlinks that point outside the root are left out. A listing of any depth, direct children included, fails with `INVALID_ARGUMENT` once it passes 100,000 entries, or once the names it returns, each a path from the listed directory, add up to more than 32 MiB. A `path` that is a file, not a directory, fails with `ALREADY_EXISTS`. The whole listing is read before the first entry is sent.

### MakeDir

```proto theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
rpc MakeDir(MakeDirRequest) returns (FileInfo);
```

Creates a directory and returns its metadata.

| Field | Type | Meaning |
| - | - | - |
| `path` | string | The directory. |
| `mode` | uint32 | Permission bits, applied exactly except that setuid and setgid are dropped. `0` means `0755`. |
| `parents` | bool | Create missing parents. Without it, a missing parent fails with `NOT_FOUND`. |

An existing directory succeeds unchanged. An existing non-directory fails with `ALREADY_EXISTS`.

### Move and Copy

```proto theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
rpc Move(TransferRequest) returns (TransferResponse);
rpc Copy(TransferRequest) returns (TransferResponse);
```

Move or copy a file, symlink or directory tree. Symlinks are transferred as links.

| Field | Type | Meaning |
| - | - | - |
| `source` | string | What to move or copy. |
| `destination` | string | Where it goes. |
| `overwrite` | bool | Replace an existing file. Never replaces a directory. |

An existing destination without `overwrite`, or a directory destination with it, fails with `ALREADY_EXISTS`. A source and destination that are the same path, or a directory moved or copied into itself, fail with `INVALID_ARGUMENT`.

A copy keeps permission bits but drops setuid and setgid.

### Remove

```proto theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
rpc Remove(RemovePathRequest) returns (RemovePathResponse);
```

Removes a file, a symlink (never its target) or a directory.

| Field | Type | Meaning |
| - | - | - |
| `path` | string | What to remove. |
| `recursive` | bool | Remove a directory and its contents. Without it, a non-empty directory fails with `ALREADY_EXISTS`. |

Removing the root itself with `recursive` empties it. Without `recursive` it fails with `ALREADY_EXISTS`.

### Read

```proto theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
rpc Read(ReadRequest) returns (stream FileChunk);
```

Streams a file. The first message carries its `info` (a `FileInfo`); the rest carry `data` in chunks of up to 256 KiB.

| Field | Type | Meaning |
| - | - | - |
| `path` | string | The file. |
| `offset` | uint64 | Byte offset to start at. |
| `length` | uint64 | Bytes to read. `0` reads to the end. |

A directory fails with `FAILED_PRECONDITION`. FIFOs, sockets and devices fail with `INVALID_ARGUMENT`.

### Write

```proto theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
rpc Write(stream WriteChunk) returns (FileInfo);
```

Writes a file from a stream of `WriteChunk` messages: one `header`, any number of `data` chunks, then one `commit`. Returns the written file's metadata.

| Message | Field | Meaning |
| - | - | - |
| `header` | `path` | The file. Missing parent directories are created. |
| | `mode` | Permission bits, applied exactly except that setuid and setgid are dropped. `0` means `0644`. |
| | `write_mode` | `WRITE_MODE_REPLACE` (default): atomically replace whatever is there. `WRITE_MODE_CREATE_ONLY`: fail with `FAILED_PRECONDITION` if the path exists. `WRITE_MODE_APPEND`: append, creating the file if needed. Any other value fails with `INVALID_ARGUMENT`. |
| `data` | | Bytes to write. |
| `commit` | `size` | Optional. When set, the commit fails with `FAILED_PRECONDITION` unless exactly this many bytes arrived. |

In `REPLACE` and `CREATE_ONLY` mode the data goes to a temporary file that appears at `path` only on commit: an unnamed `O_TMPFILE`, or a `.axe-tmp-*` file on filesystems without it. A stream that ends without a commit, for any reason (cancelled, disconnected, failed), leaves nothing behind and fails with `ABORTED`. `APPEND` writes in place as data arrives and is not atomic. Bytes written before a failure stay, and a stream that ends without a commit still fails with `ABORTED`.

Errors:

| Condition | Code |
| - | - |
| First message is not a header | `INVALID_ARGUMENT` |
| Unknown `write_mode` value | `INVALID_ARGUMENT` |
| A second header, or any message after the commit | `INVALID_ARGUMENT` |
| Stream ends without a commit | `ABORTED` |
| `commit.size` does not match | `FAILED_PRECONDITION` |
| `CREATE_ONLY` and the path exists | `FAILED_PRECONDITION` |
| The path is a directory, in `REPLACE` or `APPEND` mode | `INVALID_ARGUMENT` |
| The path is a directory, in `CREATE_ONLY` mode | `FAILED_PRECONDITION` |

### Watch

```proto theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
rpc Watch(WatchRequest) returns (stream WatchEvent);
```

Streams changes under a directory.

| Field | Type | Meaning |
| - | - | - |
| `path` | string | The directory. A missing path fails with `NOT_FOUND`, a non-directory with `INVALID_ARGUMENT`. |
| `recursive` | bool | Include subdirectories. axed adds new subdirectories as they appear. |

`WatchEvent` is one of:

| Event | Fields | Meaning |
| - | - | - |
| `started` | | The first event, sent once the watch is armed. axed reports changes made after it. |
| `change` | `kind`, `path` | `CHANGE_KIND_CREATE`, `WRITE`, `REMOVE`, `RENAME` or `CHMOD`. `path` is relative to the root. `RENAME` is reported on the old path; the new path arrives as `CREATE` when it lands inside the watched tree. |
| `error` | `message`, `terminal` | A terminal error, such as the watched directory being removed, is the last event. Others, such as a kernel queue overflow after which you should rescan, leave the watch running. |

axed gathers events in 50 ms batches and delivers them in order. It does not report temporary files from in-progress uploads, and a committed upload shows up as a `CREATE` of its path. The stream ends when the client cancels or the daemon shuts down.

At most 64 watches run at once across all APIs. Beyond that, `Watch` fails with `RESOURCE_EXHAUSTED`. axed checks the limit before the path, so with every slot taken even a watch on a missing path gets `RESOURCE_EXHAUSTED`. A failure of the underlying watch ends the stream with `INTERNAL`.

## System

### Health

```proto theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
rpc Health(HealthRequest) returns (HealthResponse);
```

| Response field | Type | Meaning |
| - | - | - |
| `ready` | bool | `false` while shutting down. |
| `eviction_pending` | bool | The daemon received `SIGTERM` while running with `--on-sigterm stay`, so the platform can suspend the sandbox instead. |
| `frozen` | bool | Processes are frozen by `Freeze`, so starts are refused until a thaw. |

### Info

```proto theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
rpc Info(InfoRequest) returns (InfoResponse);
```

| Response field | Type | Meaning |
| - | - | - |
| `version` | string | axed's version. |
| `instance_id` | string | Random id of this in-memory process table. Survives memory restores; changes on a cold boot. |
| `generation` | uint64 | Suspend and restore cycles detected since the instance started. |
| `resumed_at` | repeated Timestamp | When axed noticed the most recent resumes, at most 16, oldest first. |
| `pid1` | bool | axed is PID 1. |
| `subreaper` | bool | axed collects orphaned descendants (as PID 1 or a child subreaper). |
| `cgroup` | string | The cgroup v2 directory axed manages; empty without cgroups. |
| `root_dir` | string | The sandbox root. |
| `default_retain_bytes`, `max_retain_bytes` | uint64 | `--retain` and `--max-retain`, after adjustment. |
| `output_budget_bytes` | uint64 | `--output-budget`, after adjustment. |
| `max_processes` | uint32 | `--max-processes`. |
| `capture_budget_bytes` | uint64 | `--capture-budget`. |
| `freeze` | bool | Whether `Freeze` works. It needs cgroups. |
| `adapters` | repeated string | Provider protocols served next to `axe.v1`: `agent-sandbox`, `agent-substrate`, `mcp`. |
| `features` | repeated string | Optional behaviors this daemon has, so a client checks for a name instead of comparing versions: `exit-reason`, `live-usage`, `exec-request-id`, `error-reasons`, `configure-thaw`, `grpc-health`. Later versions add names; none is removed before 1.0 without notice. |
| `default_limits` | Limits | Limits a request that sets none gets: `--default-timeout`, `--default-memory`, `--default-max-tasks`. |
| `max_limits` | Limits | Ceilings a request may not exceed: `--max-timeout`, `--max-memory`. |

### Configure

```proto theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
rpc Configure(ConfigureRequest) returns (ConfigureResponse);
```

Applies host-provided state when a sandbox is bound or after a resume. Call it after every snapshot restore on platforms that freeze guest clocks. See [Snapshots](https://axe-engine.mintlify.site/snapshots.md).

| Field | Type | Meaning |
| - | - | - |
| `wall_time` | Timestamp | The host's current time. The guest's wall clock is stepped when it is off by more than 50 ms. Needs `CAP_SYS_TIME`. A time before 1970 or out of range fails with `INVALID_ARGUMENT`. |
| `entropy` | bytes | Credited to the kernel entropy pool, so clones of one snapshot stop sharing random state. Needs `CAP_SYS_ADMIN`. Best effort: without the capability the bytes are dropped and the call still succeeds. |
| `resumed` | bool | Record a resume the clocks did not reveal. Increments the generation. It is recorded after the clock is stepped, so a call that fails does not count as a resume. |
| `thaw` | bool | Thaw processes frozen with `Freeze`, after the clock is set and the resume recorded, so a client that resumes a sandbox can do both in one call. Without cgroups nothing can be frozen, and this does nothing. |

The whole request is checked before anything changes.

| Response field | Type | Meaning |
| - | - | - |
| `clock_correction` | Duration | How far axed stepped the wall clock, positive for forward. Unset when axed did not step it. |
| `generation` | uint64 | The generation after this call. |
| `entropy_added` | bool | Whether the entropy reached the kernel pool. False when none was sent or axed lacks `CAP_SYS_ADMIN`. |
| `thawed` | uint32 | Process trees that `thaw` thawed within 5 seconds. |

### Freeze

```proto theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
rpc Freeze(FreezeRequest) returns (FreezeResponse);
```

Freezes or thaws every running process tree through its cgroup, as a quiesce point before a snapshot. Without cgroups it fails with `FAILED_PRECONDITION`.

From a freeze until the thaw, axed refuses to start processes: `Start`, `Run`, `Exec` and the adapters' starts fail with `FAILED_PRECONDITION` (`FROZEN`). A process that started then would run while the rest are stopped, and a snapshot would catch it mid-start. Repeating a `request_id` whose process already exists still succeeds. Starts already under way when the freeze arrives finish first and are frozen with the rest.

| Field | Type | Meaning |
| - | - | - |
| `frozen` | bool | `true` freezes, `false` thaws. |
| `timeout` | Duration | How long to wait for every tree to change state. `0` means 5 seconds. A negative timeout fails with `INVALID_ARGUMENT`. |

| Response field | Type | Meaning |
| - | - | - |
| `changed` | uint32 | Trees that reached the requested state before the timeout. |
| `total` | uint32 | Running processes when the call started. |


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