> ## 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 Substrate API

> Agent Substrate's ateenv.v1alpha guest API as axed serves it: every RPC, how it maps onto the engine, and the policies axed does not implement.

Agent Substrate's guest data plane, `ateenv.v1alpha`, as axed serves it with `--agent-substrate`. It lets axed replace `ate-env-guest` inside Substrate actors. The proto is copied unchanged from agent-substrate/env: [`proto/ateenv/v1alpha/guest.proto`](https://github.com/vincent0426/axe/blob/main/proto/ateenv/v1alpha/guest.proto).

[Deploy on Agent Substrate](https://axe-engine.mintlify.site/deploy/agent-substrate.md) covers templates, eviction and snapshots.

## Enabling it

`--agent-substrate` adds `ateenv.v1alpha.ProcessService` and `ateenv.v1alpha.FileSystemService` to every gRPC listener, next to [`axe.v1`](https://axe-engine.mintlify.site/reference/native-api). The flag takes no value. It is off by default.

```sh theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
axed --agent-substrate --listen 'unix:///run/ateenv.sock?auth=none' --on-sigterm stay
```

The services use the same auth as every other gRPC service. With a token configured, send `authorization: Bearer <token>` or `x-sandboxd-token: <token>` metadata, or serve them on a non-TCP listener with `?auth=none`.

## What is supported

| RPC | Supported | Notes |
| - | - | - |
| `ProcessService.StartProcess` | Yes | `timeout` counts running time. Without one, `--default-timeout` applies, or `--max-timeout` when only that is set. |
| `ProcessService.GetProcess` | Yes | |
| `ProcessService.StreamProcessOutput` | Yes | Per-stream offsets, exact while the bytes are retained. |
| `ProcessService.WriteProcessInput` | Yes | |
| `ProcessService.SignalProcess` | Yes | Any signal number. |
| `FileSystemService.ReadFile` | Yes | Including create-on-read with `mode`. |
| `FileSystemService.WriteFile` | Yes | Offset `0` replaces atomically. |
| `GET /readyz` | Yes | On `--rest-port` (needs `--agent-sandbox=true`, the default), without a token. |

### Server-side policies

`ate-env-guest` applies these server-side policies. In axed:

| Policy in `ate-env-guest` | In axed |
| - | - |
| A cap on concurrently running processes (default 10) | `--max-processes` (default 1024) bounds processes tracked. A start evicts finished records to make room, so only running processes can fill it, and a start beyond it fails with `RESOURCE_EXHAUSTED`. |
| A cap on spooled log size | No equivalent. axed keeps output in a ring of `--retain` bytes per process (default 1 MiB). Older bytes are evicted, not capped, and no truncation notice is written into the output. |
| A default timeout for processes started without one (default 1 hour) | `--default-timeout`, off by default. `--max-timeout` also bounds what a request may ask for. |
| Running processes as an unprivileged user | `--default-user`, off by default. |

## Process ids

`process_id` is the engine's process id: an opaque 32-hex-digit string, the same id `axe.v1` uses. A process started through `ateenv` is visible through `axe.v1` and the other way round. Ids belong to one axed instance; after a cold boot they are unknown.

An empty `process_id` fails with `INVALID_ARGUMENT`; an unknown one with `NOT_FOUND`.

## ProcessService

### StartProcess

Launches a process in the background and returns its `Process` once it is running.

| Field | Meaning in axed |
| - | - |
| `command` | Program and arguments. Required; empty fails with `INVALID_ARGUMENT`. |
| `cwd` | Working directory inside `--root-dir`. Empty means the root. An absolute path under the root is accepted; an absolute path outside it, or a path that climbs above it, fails with `PERMISSION_DENIED`, as in `FileSystemService`. A missing directory fails with `NOT_FOUND`, a non-directory with `INVALID_ARGUMENT`. |
| `env` | Added to the daemon's environment. |
| `stdin` | Open a stdin pipe for `WriteProcessInput`. Without it stdin is `/dev/null`. |
| `timeout` | Kill the process tree with `SIGKILL` after this much running time. Time the sandbox spends suspended does not count, unlike the wall-clock timeout the proto describes. Unset or zero takes `--default-timeout`, or else `--max-timeout`; with neither set, there is no timeout. A negative timeout fails with `INVALID_ARGUMENT`. |

Processes run on pipes; the API has no terminal option. Each keeps `--retain` bytes of output and stays queryable after it exits, until `--max-finished` newer processes have finished or the output budget needs the space.

### GetProcess

Returns the process's current state.

`Process` fields:

| Field | Meaning |
| - | - |
| `process_id` | The engine's process id. |
| `command` | The command. |
| `pid` | Host pid of the leader. Still reported after the process exits. |
| `state` | `PROCESS_STATE_RUNNING` or `PROCESS_STATE_EXITED`. |
| `exit_code` | Valid once exited: the exit status, or 128 plus the signal number. `0` while running. |
| `started_at` | When it started. |
| `finished_at` | When it exited. Unset while running. |

### StreamProcessOutput

Streams stdout and stderr.

| Field | Meaning in axed |
| - | - |
| `stdout_offset`, `stderr_offset` | Byte offsets within each stream. Bytes before them are not delivered. Negative values mean `0`. |
| `follow` | Keep streaming until the process exits, then send a final `exit` message with the finished `Process`. Without it, axed sends the output retained so far, followed by `exit` only if the process has already exited. |

Messages carry `stdout` or `stderr` chunks of up to `--stream-chunk-size` bytes, then `exit`. axed skips output evicted before the stream reached it without notice, because the protocol has no gap message. A following stream holds the process back if the client reads slower than the process writes and retention is full. A process allows at most 64 such lossless readers at once, across all APIs; one more fails with `RESOURCE_EXHAUSTED`.

To wait for a process, follow with offsets past the end of both streams. The stream ends with `exit` and no output.

### WriteProcessInput

A client stream of stdin chunks. The first message must carry `process_id`; it is ignored after.

| Field | Meaning |
| - | - |
| `data` | Bytes to write. May be empty. |
| `close` | Close stdin after `data`. axed stops reading the stream there. |

The response's `bytes_written` is the total bytes written by this call. Writing non-empty `data` to a process started without `stdin`, or whose stdin is already closed, fails with `FAILED_PRECONDITION`; empty `data` and `close` succeed. An empty stream fails with `INVALID_ARGUMENT`.

### SignalProcess

Delivers `signal` to the process group and returns the process state as it was just before delivery, so the state is always `RUNNING`.

* `SIGNAL_UNSPECIFIED` (0) or a negative number fails with `INVALID_ARGUMENT` (`signal is required`).
* axed delivers any positive signal number, including ones the enum does not list. A number the kernel rejects fails with `INVALID_ARGUMENT`.
* A process that has exited fails with `FAILED_PRECONDITION`.

## FileSystemService

Paths are relative to `--root-dir`, or absolute under it. An absolute path outside the root fails with `PERMISSION_DENIED`, as does a path that climbs above it. An empty path fails with `INVALID_ARGUMENT`.

### ReadFile

Streams the file in chunks of up to 64 KiB.

| Field | Meaning |
| - | - |
| `path` | The file. A directory fails with `FAILED_PRECONDITION`. |
| `mode` | When nonzero and the file does not exist, axed creates it empty with these permission bits, along with missing parent directories, and the stream ends without chunks. When zero, a missing file fails with `NOT_FOUND`. axed never modifies existing files. |

### WriteFile

A client stream. axed reads `path`, `mode` and `seek_offset` from the first message only. Every message may carry a `chunk`.

| Field | Meaning |
| - | - |
| `path` | The file. Required. axed creates missing parent directories. |
| `mode` | Permission bits. `0` means `0644`. With `seek_offset` `0` they apply to the replacement file, even when a file already existed. With a positive offset they apply only when the file is created. |
| `seek_offset` | `0` replaces the file. Data goes to an unnamed `O_TMPFILE` (a `.axe-tmp-*` file on filesystems without it) that axed links into place when the stream ends cleanly, so readers never see it half written and a failed stream leaves the old file untouched. A positive offset edits the file in place, creating it if absent. Writing starts at the offset, axed extends a shorter file with zero bytes, and bytes after the written range stay. Negative fails with `INVALID_ARGUMENT`. |

The response's `bytes_written` is the total across all chunks. A stream with no messages fails with `INVALID_ARGUMENT`.

## Health and eviction

axed serves `GET /readyz` on `--rest-port`, which never needs a token and returns `503` while shutting down, as `GET /v1/health` does.

With `--on-sigterm stay`, axed keeps running on `SIGTERM` and reports `eviction_pending: true` through [`System.Health`](https://axe-engine.mintlify.site/reference/native-api#health), so the platform can suspend the actor instead of stopping it.


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