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

# axectl command line

> Every axectl command and flag, its global options and environment, how it resolves process names, and its exit codes.

`axectl` is the command-line client for AXE's native API (`axe.v1`). `axectl --help` and `axectl <command> --help` print the same commands and flags.

`axectl` talks to axed's gRPC port only. It does not use the Agent Sandbox REST port.

## Global options

These work before or after the command name.

**--addr** `string` (default: 127.0.0.1:9090)

axed's gRPC endpoint. Environment: `AXE_ADDR`.

* `host:port` for TCP, for example `axed:9090`. An address with a scheme, such as `http://axed:9090`, is used as given.
* `unix:///path` for a Unix socket.
* `vsock://cid:port` for vsock. The cid must be a number.

Connecting times out after 5 seconds, on every transport.

**--token** `string`

Bearer token, sent as `authorization: Bearer <token>` metadata on every call. Environment: `AXE_TOKEN`. Must be printable ASCII. `--help` does not print its value.

**-h, --help** `flag`

Print help.

**-V, --version** `flag`

Print the version.

## Process names and ids

Commands that take `PROCESS` accept an id or a name.

* A string of exactly 32 hex digits is an id, as printed by `run` and `ps`.
* Anything else is a name. A name refers to the running process with that name, or after it exits, the most recently finished process with that name that axed still remembers.

A name made of 32 hex digits is always read as an id. Names are unique among running processes, so a second `run --name` with a name in use fails until the first process exits.

## Exit codes

| Code | When |
| - | - |
| The process's exit code | `wait`, `exec`, and `attach` or `run -a` when the process exits while attached. |
| 128 plus the signal number | The same commands, for a process killed by a signal. `143` is `SIGTERM`, `137` is `SIGKILL`. |
| `0` | Every other command on success. Also `logs` (whatever the process did), and `attach` or `run -a` when you detach. |
| `1` | `watch` ended because of an error that stopped the watch. |
| `130` | `axectl` received `SIGINT` (Ctrl-C outside raw mode). |
| `143` | `axectl` itself received `SIGTERM`. |
| `125` | `axectl` failed: it could not connect, the daemon returned an error, an argument was invalid, or the stream of `exec`, `attach` or `run -a` ended before the process was described or before its exit arrived (`stream ended before the process was described`, `the stream ended before the process exited`). The message goes to stderr, prefixed with `axectl:`. |
| `2` | The command line did not parse. |

`axectl` clamps exit codes outside 0 to 255 to that range. `125`, `130` and `143` are ambiguous. A process can exit with any of them itself, `130` also means a process killed by `SIGINT`, and `143` a process killed by `SIGTERM`.

## Process options

`run` and `exec` take these options before the command. Everything after the first argument that is not an option, or after `--`, is the command and its arguments.

**-t, --tty** `flag`

Run on a pseudo-terminal sized to the local terminal, or 80x24 when there is none. Output from a terminal is all stdout.

**-e, --env** `KEY=VALUE, repeatable`

Add an environment variable on top of the daemon's environment.

**-w, --cwd** `path` (default: the root)

Working directory inside the sandbox root.

**-u, --user** `string`

Run as this user: a name from `/etc/passwd`, a uid, or `uid:gid`.

**--timeout** `duration`

Kill the process tree after this much running time. Time the sandbox spends suspended does not count. Uses Go duration syntax, as axed's flags do: for example `30s`, `5m`, `1h30m`, `1.5h`.

**--memory** `SIZE`

Memory ceiling: a number of bytes, or a whole number with a binary unit (`KiB`, `MiB`, `GiB`; `K`, `M`, `G` mean the same), for example `512MiB`. With cgroups this limits the whole tree; without, it is `RLIMIT_AS` per process.

**--cpus** `number`

CPU limit as a number of CPUs, for example `0.5` or `2`. The smallest value is `0.001`. `axectl` sends it to axed in millicores (`cpu_millis`, 1000 for one CPU). Requires cgroups; without them the start fails.

## Commands

### run

Start a detached process that keeps running when `axectl` exits. Prints the process id.

```sh theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
axectl run [PROCESS OPTIONS] [-a] [-i] [--name NAME] [-l KEY=VALUE]... [--retain SIZE] [--request-id KEY] [--] COMMAND [ARGS]...
```

**-a, --attach** `flag`

Attach right away instead of printing the id, with stdin forwarded. With `-t`, Ctrl-P Ctrl-Q detaches and leaves the process running. Implies `-i`.

**-i, --interactive** `flag`

Keep the process's stdin open, so a later `attach -i` can write to it. Without `-i` or `-a`, stdin is `/dev/null` unless `-t` is set; a terminal always has input.

**--name** `string`

Name, unique among running processes.

**-l, --label** `KEY=VALUE, repeatable`

Label the process. `ps -l` filters on labels.

**--retain** `SIZE` (default: 0)

Output to retain for replay, in bytes or with a binary unit, as for `--memory`. `0` uses the daemon's `--retain`. More than the daemon's `--max-retain` fails.

**--request-id** `string`

Idempotency key. Running the same command again with the same key prints the first process's id instead of starting another, so a script can retry safely. The same key with a different command or options fails with `already exists (REQUEST_ID_CONFLICT)`.

Uses `Processes.Start`, then `Processes.Attach` with `-a`.

### exec

Run a process attached to this terminal and exit with its exit code. axed kills the process if `axectl` disconnects or exits. `axectl` forwards stdin, and local end-of-file ends the process's input. For a pipe, that closes the process's stdin. On a terminal, axed sends the terminal's end-of-file character (Ctrl-D), so input piped to `exec -t` ends as well. A program that switches the terminal to raw mode, such as `bash` or `python3` with readline, can miss that Ctrl-D when it arrives before the program reads, and then keeps waiting; end such input with an explicit command such as `exit`. Ctrl-P Ctrl-Q does not detach.

With `-t` and a local terminal, `axectl` switches to raw mode. Keys, Ctrl-C included, go to the process, and `axectl` forwards window size changes. Without raw mode, Ctrl-C makes `axectl` exit with `130`, which kills the process.

```sh theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
axectl exec [PROCESS OPTIONS] [--] COMMAND [ARGS]...
```

Uses `Processes.Run` without `detach`.

### attach

Replay a process's retained output, then follow it until it exits. Exits with the process's exit code. Without `-i`, `axectl` does not read stdin, so Ctrl-P Ctrl-Q does not detach. Ctrl-C stops following, `axectl` exits with `130`, and the process keeps running.

```sh theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
axectl attach [--from OFFSET] [--lossy] [-i] PROCESS
```

**--from** `integer`

Replay from this output byte offset instead of the oldest retained byte. An offset past the end starts at the end.

**--lossy** `flag`

Never slow the process down. `axectl` skips output evicted before it reads it and reports it on stderr as `axectl: N bytes of output were dropped`. By default a slow reader holds the process back.

**-i, --interactive** `flag`

Forward stdin. On a terminal process, Ctrl-P Ctrl-Q detaches. On a terminal process with a local terminal, `axectl` switches to raw mode. Keys, Ctrl-C included, go to the remote process, and `axectl` forwards window size changes. Otherwise Ctrl-C stops following and `axectl` exits with `130`; the process keeps running.

### logs

Print a process's retained output and exit with `0`. Stdout and stderr go to the matching local streams.

```sh theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
axectl logs [-f] [--from OFFSET] PROCESS
```

**-f, --follow** `flag`

Keep following output until the process exits. Ctrl-C stops following, not the process.

**--from** `integer`

Start at this byte offset of the output instead of the oldest retained byte. The `OUTPUT` column of `ps` shows how many bytes a process has written.

`logs` reads lossily. It never slows the process and reports skipped bytes on stderr.

### ps

List processes, running and finished, in start order.

```sh theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
axectl ps [-l KEY=VALUE]...
```

**-l, --label** `KEY=VALUE, repeatable`

Only processes carrying all of these labels.

Columns:

| Column | Meaning |
| - | - |
| `ID` | The process id. |
| `NAME` | The name, or `-`. |
| `PID` | The leader's pid, or `-` once it has been reaped. |
| `STATE` | `running`, or why the process ended: `exited` (on its own), `signaled` (by a signal, `axectl kill` included), `timed-out` (by `--timeout`), `oom-killed` (by the cgroup's memory limit), `killed` (by `rm -f`), `owner-gone` (the `exec` or call that owned it ended), `shutdown` (axed stopped it) or `unknown` (its exit status was lost; `EXIT` is `-1`). |
| `EXIT` | The exit code, or `-` while running. |
| `CPU` | CPU seconds, user and system. |
| `MEM` | Memory in use while running, the peak after exit, or `-` when unknown. |
| `OUTPUT` | Offset one past the newest output byte, which is the total bytes written. |
| `COMMAND` | The command and arguments. |

`CPU` and `MEM` cover the whole tree when axed runs the process in a cgroup. Without one they cover only the leader and end in `*`, as in `0.3*`. axed reads them when `ps` asks; nothing samples in the background.

### kill

Send a signal to the process's process group.

```sh theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
axectl kill [-s SIGNAL] PROCESS
```

**-s, --signal** `string` (default: TERM)

A signal number, or one of `HUP`, `INT`, `QUIT`, `KILL`, `USR1`, `USR2`, `TERM`, `STOP`, `CONT`, `WINCH`. Names are case-insensitive and may start with `SIG`. Other signals work by number.

Signaling a process whose leader has already exited succeeds and does nothing, even while axed is still collecting its output.

### wait

Wait for a process to exit, print why it ended and its exit code, and exit with its exit code.

```sh theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
axectl wait PROCESS
```

The line uses the `STATE` words of `ps`, for example `timed-out 137` or `exited 0`.

### rm

Forget a finished process, freeing its retained output.

```sh theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
axectl rm [-f] PROCESS
```

**-f, --force** `flag`

Kill a running process tree first, wait for it, then forget it. Without `-f`, a running process fails with `failed precondition`.

### watch

Print file changes under a directory of the sandbox root, one per line, until interrupted.

```sh theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
axectl watch [-r] [PATH]
```

**PATH** `path` (default: .)

Directory to watch, relative to the root.

**-r, --recursive** `flag`

Include subdirectories, including ones created during the watch.

Each line is the change kind (`CREATE`, `WRITE`, `REMOVE`, `RENAME`, `CHMOD`) and the path relative to the root. A rename prints `RENAME` with the old path, then `CREATE` with the new path when it lands inside the watched tree.

Errors go to stderr, prefixed with `axectl: watch:`. An error that leaves the watch running, such as a kernel queue overflow, is reported and watching continues. An error that ends the watch makes `axectl` exit with `1`.

### freeze

Freeze every running process tree through its cgroup, as a quiesce point before a snapshot. Requires cgroups. Prints `N of M process trees frozen`. Waits up to 5 seconds for the trees to change state. Until the thaw, starting a process fails with `failed precondition (FROZEN)`.

```sh theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
axectl freeze [--thaw]
```

**--thaw** `flag`

Thaw instead of freezing.

### resumed

After restoring a snapshot, send axed this machine's wall time and 64 bytes of fresh entropy, and record a resume. Prints the new generation, how far the clock was stepped, and whether the entropy was added. Run it from the host side, where the clock is right.

```sh theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
axectl resumed [--no-entropy] [--thaw]
```

**--no-entropy** `flag`

Skip the entropy step.

**--thaw** `flag`

Also thaw processes frozen with `axectl freeze`, after the clock is set and the resume recorded. Adds `N process trees thawed` to the output. Does nothing without cgroups.

axed steps its wall clock if it is more than 50 ms off (needs `CAP_SYS_TIME`), then adds the entropy (needs `CAP_SYS_ADMIN`), then records the resume. Without `CAP_SYS_TIME` the command fails when the clock is off, and no resume is recorded. The entropy is best effort: without `CAP_SYS_ADMIN` it is skipped and the output says `entropy not added`.

Uses `System.Configure` with `resumed: true`. See [Snapshots](https://axe-engine.mintlify.site/snapshots.md).

### info

Print daemon state and capabilities.

```sh theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
axectl info
```

| Line | Meaning |
| - | - |
| `version` | axed's version. |
| `instance` | Instance id. It changes when axed starts fresh, such as after a cold boot. |
| `generation` | Suspend and restore cycles detected since the instance started. |
| `ready` | `false` while shutting down. |
| `eviction` | `pending` after `SIGTERM` under `--on-sigterm stay`, otherwise `-`. |
| `frozen` | Whether processes are frozen, so starts are refused. |
| `root` | The sandbox root. |
| `pid1` | Whether axed is PID 1. |
| `subreaper` | Whether axed collects orphaned descendants. |
| `cgroup` | The cgroup v2 directory axed manages, or `-`. |
| `retain` | Default and maximum retention per process, in bytes. |
| `budget` | The output budget in bytes, and the process limit. |
| `capture` | The capture budget shared by unary executions such as `Exec`, in bytes. |
| `freeze` | Whether `freeze` works (it needs cgroups). |
| `adapters` | Protocols served besides `axe.v1`, or `-`. |
| `features` | Optional behaviors the daemon has, as `System.Info` lists them. |
| `defaults` | Limits a request that sets none gets, from `--default-timeout`, `--default-memory` and `--default-max-tasks`, or `-`. |
| `maximums` | Ceilings from `--max-timeout` and `--max-memory`, or `-`. |

## Detaching

`run -a` and `attach -i` detach on Ctrl-P followed by Ctrl-Q, and exit with `0`. The process keeps running. Ctrl-P followed by any other key sends both keys. Detaching applies only when the process has a terminal (`-t`). On a process without one, `axectl` forwards every input byte unchanged, so binary input passes through intact. Docker also claims Ctrl-P Ctrl-Q, so when you run `axectl` with `docker run -it`, pass `--detach-keys` to give Docker another sequence.

## Examples

```sh theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
export AXE_ADDR=unix:///run/axe.sock
axectl run --name build -l job=ci -- make -j8
axectl logs -f build
axectl ps -l job=ci
axectl kill -s INT build
axectl wait build; echo $?
axectl rm build
axectl run -t -a --name shell -- bash
```

[Run processes](https://axe-engine.mintlify.site/processes/run.md) walks through a full session.


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