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

# Errors

> The engine's error variants, how axed maps them to gRPC status codes and REST responses, and the errno translations.

Every error the engine returns, the gRPC code and REST response each becomes, and the errors the daemon adds on top. The mapping lives in [`crates/axed/src/errors.rs`](https://github.com/vincent0426/axe/blob/main/crates/axed/src/errors.rs), and the variants in [`crates/axe/src/error.rs`](https://github.com/vincent0426/axe/blob/main/crates/axe/src/error.rs).

## Engine errors

Every fallible engine call returns `axe::Result<T>`, whose error is `axe::Error`. The variant is the category to branch on; the message is for people.

| Variant | Meaning | Examples |
| - | - | - |
| `InvalidArgument(String)` | The request is malformed or names the wrong kind of thing. | Empty command; invalid signal number; not a directory; FIFO, socket or device; path nested more than 256 levels; more than 40 symlinks; listing past its entry limit; move into itself; stdin offset plus write length overflows. |
| `NotFound(String)` | The process, path or program does not exist. | Unknown process; missing path or parent; command not found. |
| `PermissionDenied(String)` | Confinement or the kernel refused. | Path leaves the root; archive entry escapes; the kernel refused a signal; program not executable. |
| `FailedPrecondition(String)` | The request is valid but the state does not allow it. | CPU limit or freeze without cgroups; supervisor shutting down; process still running; no stdin; PTY has no EOF to close; resize without a PTY; create-only path exists; stdin offset past what was accepted. |
| `Conflict(String)` | Something already exists or is in the way. | Destination exists; directory not empty; path exists and is not a directory. |
| `ResourceExhausted(String)` | A bound was reached. | Archive past its limits; a 65th lossless reader of one process's output; a directory of more than 1,048,576 entries to copy. |
| `NameInUse(String)` | A kind of conflict: the name belongs to a running process. | Spawning with a name in use. |
| `RequestIdConflict(String)` | A kind of conflict: the request id was used for a spawn with a different command or options. | Repeating a `request_id` with another command. |
| `RequestExpired(String)` | A kind of failed precondition: the process a request id started was evicted, so its outcome is gone. | Repeating a `request_id` after eviction; repeating a keyed capture whose output was evicted. |
| `BudgetExhausted(String)` | A kind of resource exhaustion: running processes hold the whole output budget or every process slot. | Spawning past `max_processes` running processes. |
| `ProcessExited(String)` | A kind of failed precondition: the process has exited. | Writing stdin or resizing after exit; exiting before reading all of a pending stdin write. |
| `LimitExceeded(String)` | A kind of invalid argument: a requested limit is above what is allowed. | `retain_bytes` above the maximum; a limit above an axed ceiling such as `--max-memory`. |
| `Frozen(String)` | A kind of failed precondition: processes are frozen. | Spawning between `set_frozen(true)` and the thaw. |
| `Io { context, source }` | An operating-system error with no specific category. Displays as `<context>: <source>`. | `write: No space left on device`. |

## gRPC status codes

Every gRPC API (`axe.v1`, `process.v1`, `watcher.v1`, `ateenv.v1alpha`) maps engine errors the same way. The message is the error's display text.

| Engine error | gRPC code |
| - | - |
| `InvalidArgument` | `INVALID_ARGUMENT` |
| `NotFound` | `NOT_FOUND` |
| `PermissionDenied` | `PERMISSION_DENIED` |
| `FailedPrecondition` | `FAILED_PRECONDITION` |
| `Conflict` | `ALREADY_EXISTS` |
| `ResourceExhausted` | `RESOURCE_EXHAUSTED` |
| `NameInUse`, `RequestIdConflict` | `ALREADY_EXISTS` |
| `RequestExpired`, `ProcessExited`, `Frozen` | `FAILED_PRECONDITION` |
| `BudgetExhausted` | `RESOURCE_EXHAUSTED` |
| `LimitExceeded` | `INVALID_ARGUMENT` |

`Io` errors map by errno:

| errno | gRPC code |
| - | - |
| `ENOENT`, `ENOTDIR` | `NOT_FOUND` |
| `EACCES`, `EPERM`, `EROFS` | `PERMISSION_DENIED` |
| `ENOSPC`, `EDQUOT` | `RESOURCE_EXHAUSTED` |
| `ENAMETOOLONG`, `ELOOP` | `INVALID_ARGUMENT` |
| `EEXIST` | `ALREADY_EXISTS` |
| `ENOTEMPTY`, `EISDIR` | `FAILED_PRECONDITION` |
| Anything else, or no errno | `INTERNAL` |

> [!NOTE]
>
> `Conflict` becomes `ALREADY_EXISTS` in gRPC even when nothing "exists" in the usual sense, for example removing a non-empty directory without `recursive`.

## Reasons

The errors a client branches on carry a [`google.rpc.ErrorInfo`](https://github.com/googleapis/googleapis/blob/master/google/rpc/error_details.proto) in the status details (the `grpc-status-details-bin` trailer), with domain `axe.v1` and a reason. Read it with your gRPC library's rich error support: `status.Details()` in Go, `tonic_types::StatusExt::get_details_error_info` in Rust, `grpc_status.rpc_status.from_call` in Python. The code alone stays enough for clients that ignore details.

| Reason | Code | When |
| - | - | - |
| `NAME_IN_USE` | `ALREADY_EXISTS` | A start names a process that is still running. |
| `REQUEST_ID_CONFLICT` | `ALREADY_EXISTS` | A `request_id` repeated with a different request. |
| `REQUEST_EXPIRED` | `FAILED_PRECONDITION` | A `request_id` repeated after its process, or for `Exec` its output, was evicted. |
| `BUDGET_EXHAUSTED` | `RESOURCE_EXHAUSTED` | Running processes hold the whole output budget or the process table. Retry once a process exits or is removed. |
| `PROCESS_EXITED` | `FAILED_PRECONDITION` | Stdin or a resize for a process that has exited. |
| `LIMIT_EXCEEDED` | `INVALID_ARGUMENT` | `retain_bytes` above `--max-retain`, or a limit above `--max-timeout` or `--max-memory`. The message names the flag. |
| `FROZEN` | `FAILED_PRECONDITION` | A start while processes are frozen. Thaw with `Freeze` or `Configure`. |
| `INSTANCE_CHANGED` | `NOT_FOUND` | A `ProcessRef` whose `instance_id` is not the daemon's: it cold-booted and the process is gone. |

The adapters' gRPC APIs carry the same details on the same errors; their clients may ignore them.

## REST responses

The Agent Sandbox REST API returns errors as JSON with `Content-Type: application/json`:

```json theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
{"code":"NOT_FOUND","message":"path does not exist under the root"}
```

| Engine error | HTTP status | `code` | `message` |
| - | - | - | - |
| `InvalidArgument` | 400 | `INVALID_ARGUMENT` | The error's text |
| `NotFound` | 404 | `NOT_FOUND` | The error's text |
| `PermissionDenied` | 403 | `PERMISSION_DENIED` | The error's text |
| `FailedPrecondition` | 412 | `FAILED_PRECONDITION` | The error's text |
| `Conflict` | 409 | `CONFLICT` | The error's text |
| `ResourceExhausted` | 413 | `RESOURCE_EXHAUSTED` | The error's text |

The finer variants take their category's row: `NameInUse` and `RequestIdConflict` as `Conflict`, `RequestExpired`, `ProcessExited` and `Frozen` as `FailedPrecondition`, `BudgetExhausted` as `ResourceExhausted`, and `LimitExceeded` as `InvalidArgument`.

`Io` errors map by errno. Several replace the message with a fixed one, so host paths and kernel wording do not leak to clients:

| errno | HTTP status | `code` | `message` |
| - | - | - | - |
| `ENOENT`, `ENOTDIR` | 404 | `NOT_FOUND` | `path does not exist within the sandbox` |
| `EACCES`, `EPERM`, `EROFS` | 403 | `PERMISSION_DENIED` | `permission denied` |
| `ENOSPC`, `EDQUOT` | 507 | `RESOURCE_EXHAUSTED` | `no space left in the sandbox filesystem` |
| `ENAMETOOLONG` | 400 | `INVALID_ARGUMENT` | `path or path component is too long for the sandbox filesystem` |
| `ELOOP` | 400 | `INVALID_ARGUMENT` | `too many levels of symbolic links` |
| `EEXIST`, `ENOTEMPTY` | 409 | `CONFLICT` | The error's text |
| `EISDIR` | 409 | `CONFLICT` | `path is a directory, not a file` |
| Anything else, or no errno | 500 | `INTERNAL` | The error's text |

> [!NOTE]
>
> gRPC and REST classify each errno the same way, but gRPC has no single code for `CONFLICT`. `EEXIST` is `ALREADY_EXISTS` over gRPC, while `ENOTEMPTY` and `EISDIR` are `FAILED_PRECONDITION`. The fixed messages apply to REST only.

### Errors the REST layer adds

| Status | `code` or body | When |
| - | - | - |
| 400 | `INVALID_ARGUMENT` | A bad query parameter or header, a malformed multipart body, a stalled upload, or a missing `destination`. |
| 401 | `UNAUTHENTICATED`, `missing or invalid bearer token` | No valid token. Sent with `WWW-Authenticate: Bearer realm="sandboxd"`. |
| 404 | `NOT_FOUND`, `unknown action; use :move or :copy` | `POST` to a path without `:move` or `:copy`. |
| 404 | Empty body | An unknown endpoint. |
| 405 | Plain text `method not allowed`, with `Allow` | An unsupported method. |
| 304, 412 | Empty body | Conditional `GET` with `If-Modified-Since` or `If-Unmodified-Since`. |
| 416 | Plain text `invalid range: failed to overlap` | A `Range` that cannot be satisfied. |
| 503 | `UNAVAILABLE`, `sandboxd is shutting down` | `GET /v1/health` or `GET /readyz` during shutdown. |

## Errors the gRPC layer adds

These do not come from the engine.

| Code | API | When |
| - | - | - |
| `UNAUTHENTICATED` | All | No valid token: `missing or invalid bearer token`. |
| `INVALID_ARGUMENT` | All | Missing required fields, non-positive limits or signals, `ProcessRef` without an id or name, an empty client stream, a `Files.Write` stream that does not start with a header or sends anything after its commit, a `Files.Write` header with an unknown `write_mode`. |
| `NOT_FOUND` | All | Unknown process id or name. |
| `ABORTED` | `axe.v1` | `Files.Write` ended without a commit. |
| `FAILED_PRECONDITION` | `axe.v1` | `Files.Read` on a directory; `Files.Write` commit size mismatch. |
| `FAILED_PRECONDITION` | `ateenv.v1alpha` | `SignalProcess` on an exited process; `ReadFile` on a directory. |
| `FAILED_PRECONDITION` | `process.v1` | Any `ResizeTTY` failure: `failed to resize TTY: ...`. |
| `RESOURCE_EXHAUSTED` | `axe.v1`, `watcher.v1` | 64 watches already running across all APIs. axed checks the slot before the path, so this also answers a watch on a path that does not exist. |
| `RESOURCE_EXHAUSTED` | `process.v1` | `Execute` exceeded its time limit, or its output was truncated. |
| `INTERNAL` | `axe.v1`, `watcher.v1` | A watch failed after it started: `watch failed: ...`. |

## MCP

A tool that fails returns a result with `isError: true` and the error's text as its content, for the model to read. It carries no gRPC code or reason. Protocol failures are JSON-RPC errors:

| Code | When |
| - | - |
| `-32700` | The body is not JSON. |
| `-32600` | Not a single JSON-RPC request or notification, such as a batch. Also the body of a `401` (no valid token, with `WWW-Authenticate: Bearer`) and of a `403` (a request with an `Origin` header to an endpoint without a token). |
| `-32601` | Unknown method. |
| `-32602` | Bad `params`, or an unknown tool. |
| `-32020` | The `MCP-Protocol-Version` or `Mcp-Method` header does not match the request (protocol 2026-07-28). |
| `-32022` | Unsupported protocol version. `data` lists the supported ones. |

See [Agents over MCP](https://axe-engine.mintlify.site/deploy/mcp.md).

## axectl

`axectl` prints a daemon error as `axectl: <kind>: <message>`, where `<kind>` names the gRPC code (`not found`, `invalid argument`, `permission denied`, `failed precondition`, `already exists`, `unauthenticated`, `unavailable`, `resource exhausted`, or `error`), followed by the reason in parentheses when there is one, as in `axectl: already exists (NAME_IN_USE): ...`. It exits with 125. See [axectl exit codes](https://axe-engine.mintlify.site/reference/axectl.md#exit-codes).

## In Rust

Match on the variant:

```rust theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
use std::io::Read;

use axe::fs::{Opened, Root};

fn read_config(root: &Root) -> axe::Result<Option<String>> {
    let mut file = match root.open("config.toml") {
        Ok(Opened::File(file, _)) => file,
        Ok(Opened::Directory(_)) => return Err(axe::Error::InvalidArgument("config.toml is a directory".into())),
        Err(axe::Error::NotFound(_)) => return Ok(None),
        Err(e) => return Err(e),
    };
    let mut text = String::new();
    file.read_to_string(&mut text).map_err(|e| axe::Error::io("read config.toml", e))?;
    Ok(Some(text))
}

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let root = Root::new("/tmp/agent-workspace")?;
    println!("{:?}", read_config(&root)?);
    Ok(())
}
```

`axe::Error::io(context, source)` builds an `Io` error from a `std::io::Error`. `Error` implements `std::error::Error`, so `?` converts it into `Box<dyn std::error::Error>`.


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