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

# Agent Sandbox API

> The sandboxd-compatible API axed serves: the REST endpoints on the REST port, and the process.v1 and watcher.v1 gRPC services.

The Kubernetes Agent Sandbox runtime API as axed serves it: the REST endpoints and the `process.v1` and `watcher.v1` gRPC services. It is wire-compatible with sandboxd. [sandboxd compatibility](https://axe-engine.mintlify.site/reference/sandboxd-compatibility.md) lists every intentional difference.

The API is on by default. Turn it off with `--agent-sandbox=false`, which closes the REST port and removes the two gRPC services.

| Interface | Where |
| - | - |
| REST: `/v1/health`, `/v1/metadata`, `/v1/files` | `--listen-host`:`--rest-port`, default `0.0.0.0:8080`. HTTP/1.1 and cleartext HTTP/2. |
| gRPC: `process.v1.ProcessService`, `watcher.v1.FileWatcherService` | Every gRPC listener, default `0.0.0.0:9090`, next to [`axe.v1`](https://axe-engine.mintlify.site/reference/native-api). |

The protos are copied unchanged from upstream: [`proto/process/v1/process.proto`](https://github.com/vincent0426/axe/blob/main/proto/process/v1/process.proto) and [`proto/watcher/v1/watcher.proto`](https://github.com/vincent0426/axe/blob/main/proto/watcher/v1/watcher.proto).

## Authentication

With `--auth-token-file` or `--auth-token-sha256` set, every request needs the token except `GET /v1/health` and `GET /readyz`. Send either header (as gRPC metadata on gRPC calls):

```http theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
Authorization: Bearer <token>
X-Sandboxd-Token: <token>
```

A REST request without a valid token gets:

```http theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
HTTP/1.1 401 Unauthorized
Content-Type: application/json
WWW-Authenticate: Bearer realm="sandboxd"

{"code":"UNAUTHENTICATED","message":"missing or invalid bearer token"}
```

A gRPC call gets `UNAUTHENTICATED`.

## REST conventions

* **Errors** are JSON with `Content-Type: application/json`: `{"code": "...", "message": "..."}`, followed by a newline. [Errors](https://axe-engine.mintlify.site/reference/errors.md) lists every code and status.
* **Success without a body** is `204 No Content`. This covers every `PUT`, `DELETE` and `POST`.
* **Unknown paths** return `404` with an empty body.
* **Unsupported methods** return `405` with an `Allow` header and the plain-text body `method not allowed`.
* **Booleans** in the query accept `1`, `t`, `T`, `TRUE`, `true`, `True` and `0`, `f`, `F`, `FALSE`, `false`, `False`. An empty value or an absent parameter is `false`. Anything else is `400 INVALID_ARGUMENT` with the message `<name> "<value>" must be a boolean`.
* **Timeouts.** A connection that waits `--http-idle-timeout` (default `60s`) for a request, has writes stuck that long, or stalls an upload that long is closed. Over HTTP/2, a connection with no request open that receives nothing but keepalive pings for that long is closed too.
* **Query strings** are parsed as Go's `url.ParseQuery` parses them: a parameter with a malformed `%` escape or a `;` is dropped, and the first of repeated parameters counts.

## GET /v1/health

Readiness. Never needs the token. Accepts `GET` and `HEAD`.

**200** `application/json`

```json theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
{"status":"ok","uptime_seconds":42}
```

`uptime_seconds` counts from daemon start.

**503** `application/json`

While shutting down: `{"code":"UNAVAILABLE","message":"sandboxd is shutting down"}`.

## GET /v1/metadata

Environment variables of the daemon whose names start with `--metadata-env-prefix` (default `SANDBOX_`). axed leaves out names containing `TOKEN`, `SECRET`, `PASSWORD`, `PASSWD`, `CRED`, `KEY`, `AUTH`, `BEARER`, `PRIVATE` or `CERT`, in any case. Accepts `GET` and `HEAD`.

**200** `application/json`

```json theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
{"env":{"SANDBOX_ID":"sb-123","SANDBOX_REGION":"us-east1"}}
```

## `/v1/files/{path}`

`{path}` is everything after `/v1/files/`, percent-decoded. `/v1/files` and `/v1/files/` name the root. A path that is not valid UTF-8 after decoding is `400`. Paths resolve inside `--root-dir`. axed strips the root from an absolute path under the root, takes any other absolute path relative to the root, and cleans `.` and `..` lexically. A path that climbs above the root is `403 PERMISSION_DENIED`. axed follows symlinks only while they stay inside the root.

Methods: `GET`, `HEAD`, `PUT`, `DELETE`, `POST`.

### File metadata

`stat=true` and directory listings return entries with these fields:

| Field | Type | Meaning |
| - | - | - |
| `name` | string | For `stat`, the last path component (`/` for the root). In a listing, the path relative to the listed directory. |
| `size` | integer | Size in bytes. |
| `type` | string | `directory` or `file`. FIFOs, sockets and devices are reported as `file`. |
| `modified_at` | string | RFC 3339 in UTC with trailing fractional zeros trimmed, for example `2026-11-30T00:22:16.4005Z`. |
| `mode` | string | Permission bits as four octal digits, for example `0644`. |

### GET: download, list or stat

```http theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
GET /v1/files/{path}?type=&stat=&recursive=&max_depth=
```

**type** `file | directory`

Require the path to be this kind. A mismatch is `409 CONFLICT` (`path is a directory, not a file` or `path is a file, not a directory`). Any other value is `400`.

**stat** `boolean`

Return the path's metadata as one JSON entry instead of its contents.

**recursive** `boolean`

List a directory recursively instead of its direct children.

**max\_depth** `positive integer`

With `recursive`, how deep to list: `1` is direct children. Unlimited when absent. Has no effect without `recursive`, but axed still validates it. Zero, negative or non-numeric values are `400`.

**A file** streams as `200` with `Content-Type: application/octet-stream`, `Content-Length`, `Accept-Ranges: bytes` and `Last-Modified`. Conditional and range requests follow Go's `http.ServeContent`:

| Request header | Behavior |
| - | - |
| `If-Match` | `412` with an empty body unless the list contains `*`, since files have no ETag. |
| `If-Unmodified-Since` | Without `If-Match`: `412` with an empty body if the file changed after the date. |
| `If-None-Match` | `304` with an empty body if the list contains `*`. Any other value means the file is sent, whatever `If-Modified-Since` says. |
| `If-Modified-Since` | Without `If-None-Match`: `304` with an empty body if the file has not changed since the date. |
| `Range: bytes=a-b`, `a-`, `-n` | `206` with `Content-Range: bytes a-b/size`. |
| `Range` with several ranges | `206` with a `multipart/byteranges` body, one part per range. Ranges that together exceed the file's size are ignored: a full `200`. |
| `Range` that starts past the end of the file | `416` with `Content-Range: bytes */size` and the body `invalid range: failed to overlap`. An empty file answers `200` instead. |
| Malformed `Range`, or not in `bytes=` units | `416` with the body `invalid range`. |
| `If-Range` | The range applies only if the value is a date in the same second as the file's modification time. An entity tag never matches. |

Dates compare at one-second granularity, as `Last-Modified` carries no fraction. A file modified exactly at the Unix epoch counts as having no known modification time: it gets no `Last-Modified`, and `If-Modified-Since` and `If-Unmodified-Since` are ignored. `HEAD` returns the same headers without a body.

**A directory** returns `200` with a listing. Without `recursive` it lists direct children. Entries are in lexical order, each directory before its contents. Symlinks show their target's metadata and are never descended into; broken symlinks and ones that point outside the root are left out. A recursive listing deeper than one level that passes 10,000 entries is `400`; limit the depth or list a subdirectory. A listing of direct children is `400` only when the directory holds more than 1,048,576 entries. Any listing is `400` once the names it returns, each a path from the listed directory, add up to more than 32 MiB.

```json theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
{"path":"/notes","entries":[{"name":"hello.txt","size":5,"type":"file","modified_at":"2026-11-30T00:22:16.4005Z","mode":"0644"}]}
```

`path` is the request path with a leading `/`.

| Status | When |
| - | - |
| `404 NOT_FOUND` | The path does not exist. |
| `403 PERMISSION_DENIED` | The path leaves the root, or the filesystem denies access. |
| `400 INVALID_ARGUMENT` | A FIFO, socket or device, or bad parameters. |

### PUT: upload, make a directory, or extract

```http theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
PUT /v1/files/{path}?type=&mode=&append=&parents=&extract=
```

The body is the file's contents: raw, or the part named `file` of a `multipart/form-data` body (other parts are skipped). There is no size limit. On success, every form returns `204`.

**type** `file | directory`

`directory` creates a directory instead of uploading. `file` makes a directory at the path a `409` instead of a `400`.

**mode** `string`

Permission bits as exactly four octal digits starting with `0`, matching `^0[0-7]{3}$`, for example `0600`. axed applies it exactly and ignores the umask. Default `0644` for files, `0755` for directories and for `extract`.

**append** `boolean`

Append to the file, creating it if needed, instead of replacing it. Not atomic.

**parents** `boolean`

With `type=directory`, create missing parents.

**extract** `tar`

Unpack the body, a tar or gzipped tar archive, into the directory at `{path}`, creating it. Entries may not escape the directory, even through symlinks the archive creates. At most 100,000 entries and 1 GiB of file data, and at most 32 KiB of header, long-name, long-link and PAX records for any one entry. Setuid and setgid bits are dropped from extracted modes. Cannot be combined with `append`, `type` or `If-None-Match`.

**If-None-Match** `*`

Create only: fail with `412 FAILED_PRECONDITION` (`path already exists`) if anything exists at the path. Only `*` is accepted; any other value is `400`. Not allowed with `type=directory`. With `append`, `append` is ignored and the upload is create-only.

axed writes a regular upload to an unnamed `O_TMPFILE` (a `.axe-tmp-*` file on filesystems without it) and links it into place when the body is complete, so the path never holds a partial file, watchers never report the temporary file, and a failed upload leaves nothing. axed creates missing parent directories.

| Status | When |
| - | - |
| `204` | Success. |
| `400 INVALID_ARGUMENT` | Bad parameters; `append` or `If-None-Match` with `type=directory`; `extract` combined with other options; a multipart body without a `file` part; a stalled or broken body; uploading to a path that is a directory (without `type=file`). |
| `403 PERMISSION_DENIED` | The path leaves the root; the filesystem denies access or is read-only; an archive entry escapes. |
| `404 NOT_FOUND` | `type=directory` without `parents` and the parent is missing. |
| `409 CONFLICT` | `type=file` on a directory; `type=directory` on an existing non-directory; an archive entry conflicts with an existing directory. |
| `412 FAILED_PRECONDITION` | `If-None-Match: *` and the path exists. |
| `413 RESOURCE_EXHAUSTED` | The archive exceeds its limits. |
| `507 RESOURCE_EXHAUSTED` | No space left on the filesystem, or quota exceeded. |

An existing directory with `type=directory` succeeds unchanged.

### DELETE

```http theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
DELETE /v1/files/{path}?recursive=
```

**recursive** `boolean`

Delete a directory and its contents. Deleting the root with `recursive` empties it.

Deletes a file, a symlink (never its target) or a directory. axed validates parameters before it touches the filesystem.

| Status | When |
| - | - |
| `204` | Deleted. |
| `404 NOT_FOUND` | The path does not exist. |
| `409 CONFLICT` | A non-empty directory without `recursive`, or the root without `recursive`. |
| `403 PERMISSION_DENIED` | The path leaves the root, or the filesystem denies it. |

### POST: move or copy

```http theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
POST /v1/files/{path}:move?destination=&overwrite=
POST /v1/files/{path}:copy?destination=&overwrite=
```

Moves or copies the file, symlink or directory tree at `{path}`. Symlinks are transferred as links.

**destination** `path` *required*

Where it goes. Missing or empty is `400` (`destination is required`).

**overwrite** `boolean`

Replace an existing file. Never replaces a directory.

| Status | When |
| - | - |
| `204` | Done. |
| `400 INVALID_ARGUMENT` | No destination; source and destination are the same; a directory into itself. |
| `404 NOT_FOUND` | The source does not exist, or the action is not `:move` or `:copy` (`unknown action; use :move or :copy`). |
| `409 CONFLICT` | The destination exists without `overwrite`, or is a directory. |

### Examples

```sh theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
curl localhost:8080/v1/health
curl -X PUT --data-binary @report.pdf 'localhost:8080/v1/files/out/report.pdf?mode=0600'
curl -X PUT -F file=@notes.txt localhost:8080/v1/files/notes.txt
curl -X PUT -H 'If-None-Match: *' --data-binary 'once' localhost:8080/v1/files/lock
curl -X PUT 'localhost:8080/v1/files/a/b/c?type=directory&parents=true'
tar cz src | curl -X PUT --data-binary @- 'localhost:8080/v1/files/src?extract=tar'
curl 'localhost:8080/v1/files/src?recursive=true&max_depth=2'
curl -H 'Range: bytes=0-99' localhost:8080/v1/files/log.txt
curl -X POST 'localhost:8080/v1/files/out/report.pdf:copy?destination=backup/report.pdf'
curl -X DELETE 'localhost:8080/v1/files/src?recursive=true'
```

## process.v1.ProcessService

As in sandboxd, processes that a command leaves running when it exits on its own, such as `server &`, keep running after `Start` or `Execute` returns. They die with the command when the client disconnects from `Start` first, when a time limit kills it, and when axed shuts down with cgroups. Once the command exits, axed waits up to 5 seconds for output that they keep open, then reports the exit.

Process ids in this API are integers (`int32`), not `axe.v1`'s 32-hex-digit string ids. The adapter gives each process started through `Start` the next unused number, from 1, and reports it in the stream's `init` event. `WriteStdin`, `SendSignal` and `ResizeTTY` find a process by that number while axed tracks it, and answer `NOT_FOUND` otherwise. Processes started through `axe.v1` or `ateenv`, and `Execute` runs, take no number.

### Start

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

Runs a command and streams its output. If the client cancels or disconnects before the process exits, axed kills the process tree. axed forgets the process when it exits, so its id is unknown afterwards.

| Field | Type | Meaning |
| - | - | - |
| `config.command` | repeated string | Program and arguments. Required. |
| `config.env_vars` | map | Added to the daemon's environment. |
| `config.cwd` | optional string | Working directory inside the root. Unset or empty means the root. As in sandboxd, axed takes an absolute path outside the root relative to the root; a path that climbs above the root is `PERMISSION_DENIED`. |
| `pty` | optional PTY | Run on a pseudo-terminal of `cols` by `rows`. Zero keeps the kernel's default size. Without it, the process gets pipes with stdin open. |

`StartResponse` events, in order:

| Event | Meaning |
| - | - |
| `init.process_id` | First. The id for `WriteStdin`, `SendSignal` and `ResizeTTY`. |
| `stdout`, `stderr` | Output chunks, up to `--stream-chunk-size` bytes each. A PTY's output is all `stdout`. |
| `exit.exit_code` | Last. The exit status, or 128 plus the signal number. |

The reader is lossless. A slow client holds the process back once retention is full.

### Execute

```proto theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
rpc Execute(ExecuteRequest) returns (ExecuteResponse);
```

Runs a command to completion and returns `exit_code`, `stdout` and `stderr`. The time and byte limits are the deployment defaults (`--execute-default-*`, or the maximums when no default is set). axed caps output at 256 MiB per stream even with no limit configured.

| Outcome | Result |
| - | - |
| Completed within limits | `ExecuteResponse` |
| Time limit exceeded | `RESOURCE_EXHAUSTED`: `Execute exceeded its execution time limit; ExecuteWithLimits reports structured outcomes` |
| Output truncated | `RESOURCE_EXHAUSTED`: `Execute output was truncated by deployment policy; ExecuteWithLimits reports retained output` |

axed kills the process tree if the call is cancelled.

### ExecuteWithLimits

```proto theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
rpc ExecuteWithLimits(ExecuteWithLimitsRequest) returns (ExecuteWithLimitsResponse);
```

Runs a command with bounded output and reports the outcome instead of failing.

| Field | Type | Meaning |
| - | - | - |
| `config` | ProcessConfig | What to run. |
| `stdout_limit_bytes` | optional uint64 | Bytes kept from stdout. Unset uses `--execute-default-stdout-limit-bytes`, or `--execute-max-stdout-limit-bytes` when no default is set. Must be positive and at most the maximum when one is set; otherwise `INVALID_ARGUMENT`. Whatever the request or flags say, axed keeps at most 256 MiB. |
| `stderr_limit_bytes` | optional uint64 | The same for stderr. |
| `time_limit` | Duration | Kill the tree after this much running time. Unset uses `--execute-default-time-limit`, or `--execute-max-time-limit` when no default is set. Must be a valid protobuf duration, positive, at most about 292 years (Go's `time.Duration`), and at most `--execute-max-time-limit` when that is set; otherwise `INVALID_ARGUMENT`. |

| Response field | Type | Meaning |
| - | - | - |
| `exit_code` | int32 | The exit status, or 128 plus the signal number. |
| `stdout`, `stderr` | bytes | A prefix of each stream. axed drains and discards the rest. |
| `termination_reason` | enum | `EXECUTE_TERMINATION_REASON_EXITED`, or `EXECUTE_TERMINATION_REASON_TIME_LIMIT_EXCEEDED` when the time limit killed it. |
| `elapsed_duration` | Duration | Wall time from start to exit. |
| `stdout_truncated`, `stderr_truncated` | bool | Output past the limit was dropped. |

### WriteStdin

```proto theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
rpc WriteStdin(WriteStdinRequest) returns (WriteStdinResponse);
```

Writes `input` bytes to the process's stdin, or closes it with `eof`. An empty payload does nothing. Output in response arrives on the `Start` stream.

| Condition | Code |
| - | - |
| Unknown process, including a `Start` process that has finished | `NOT_FOUND` |
| `eof` on a PTY process (write `0x04` instead) | `FAILED_PRECONDITION` |
| Writing after `eof` | `FAILED_PRECONDITION` |

A second `eof` succeeds and does nothing.

### SendSignal

```proto theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
rpc SendSignal(SendSignalRequest) returns (SendSignalResponse);
```

Sends `SIGNAL_SIGINT`, `SIGNAL_SIGTERM` or `SIGNAL_SIGKILL` to the process group. `SIGNAL_UNSPECIFIED` or any other value is `INVALID_ARGUMENT`. An unknown process is `NOT_FOUND`.

### ResizeTTY

```proto theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
rpc ResizeTTY(ResizeTTYRequest) returns (ResizeTTYResponse);
```

Sets the PTY size to `cols` by `rows`. Fails with `FAILED_PRECONDITION` (`failed to resize TTY: ...`) when the process has no PTY or has exited. An unknown process is `NOT_FOUND`.

## watcher.v1.FileWatcherService

### WatchDir

```proto theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
rpc WatchDir(WatchDirRequest) returns (stream FileEvent);
```

Streams changes under a directory.

| Field | Type | Meaning |
| - | - | - |
| `path` | string | Directory to watch, relative to the root. Absolute paths follow the same rules as the REST API. |
| `recursive` | bool | Include subdirectories. axed adds new subdirectories as they appear and drops removed ones. |

| Condition | Code |
| - | - |
| The path does not exist | `NOT_FOUND`: `watch path does not exist: <path>` |
| The path is not a directory | `INVALID_ARGUMENT`: `watch path is not a directory: <path>` |
| The path leaves the root | `PERMISSION_DENIED` |
| 64 watches already running across all APIs | `RESOURCE_EXHAUSTED` |

`FileEvent` has `type`, `path` (relative to the root) and `error`:

| Type | Meaning |
| - | - |
| `FILE_EVENT_TYPE_CREATE` | A file or directory was created. |
| `FILE_EVENT_TYPE_WRITE` | A file's contents changed. |
| `FILE_EVENT_TYPE_REMOVE` | A file or directory was removed. |
| `FILE_EVENT_TYPE_RENAME` | Renamed or moved; `path` is the old path. The new path arrives as a separate `CREATE` when it lands inside the watched tree. |
| `FILE_EVENT_TYPE_CHMOD` | Permissions or ownership changed. |
| `FILE_EVENT_TYPE_ERROR` | `error` carries a message. A terminal error, such as the watched directory being removed, is the last event before the stream closes. Others, such as a queue overflow or an unwatchable subdirectory, arrive mid-stream and the watch continues. |

axed batches events in 250 ms windows and delivers them in order. It detects removal of the watched directory from the directory's own inotify events, not by watching its parent. It does not report temporary files from in-progress uploads. The stream ends when the client disconnects, after a terminal error, or when axed shuts down.


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