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

# Containers and hosts

> Run axed in a plain container or on a host: as PID 1 or under an init, with or without cgroups, as a non-root user.

This page covers running axed in an ordinary Linux container (runc, crun) or directly on a host: whether to make it PID 1, how it uses cgroups, running as non-root, and resource limits.

## PID 1 or under an init

axed is designed to be the container's first process, and needs no init such as tini.

* **As PID 1**, axed reaps every orphan in the PID namespace, and can take over the container's cgroup.
* **Under another init or on a host**, axed registers itself as a child subreaper, so orphaned grandchildren of the processes it starts still come back to it. Whoever is PID 1 reaps orphans from elsewhere.

`axectl info` shows which applies:

```text theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
pid1           true
subreaper      true
```

On shutdown, axed sends SIGTERM to every running process, kills the whole tree of any still running after 2 seconds, and bounds the whole shutdown by `--shutdown-timeout` (default `10s`). As PID 1, its exit also makes the kernel kill whatever is left in the PID namespace.

SIGTERM and SIGINT shut axed down. To keep running on SIGTERM, for platforms that suspend instead of stopping, use `--on-sigterm=stay`. See [Agent Substrate](https://axe-engine.mintlify.site/deploy/agent-substrate.md).

## Cgroups

With a writable, delegated cgroup v2 subtree, axed gives every process its own cgroup. That gives:

* a kill that reaches every descendant (`cgroup.kill`),
* memory, CPU and task limits for the whole process tree,
* OOM detection, reported as the `oom-killed` state,
* freezing every process before a snapshot (`axectl freeze`).

Without cgroups, axed kills the process group plus every descendant it can find through `/proc`, maps memory limits to `RLIMIT_AS` (per process) and task limits to `RLIMIT_NPROC` (which counts every process of the user), and refuses CPU limits and freezing.

**--cgroups** `auto | off | required` (default: auto)

`auto` uses cgroups when axed owns a writable cgroup v2 subtree and logs `cgroups unavailable; using process groups and rlimits` otherwise. `off` never uses them. `required` refuses to start without them.

### What delegation means

axed takes over the cgroup it runs in. It moves itself into an `axed` child cgroup, enables the `cpu`, `memory` and `pids` controllers that are available, and creates one child cgroup per process. For that it needs:

* cgroup v2 mounted in unified mode at `/sys/fs/cgroup`,
* write access to its own cgroup directory, which usually means running as root or as the user the cgroup was delegated to,
* its cgroup to itself. axed refuses to take over a cgroup shared with other processes unless it is PID 1, because moving them would surprise their owner.

A default Docker container mounts `/sys/fs/cgroup` read-only, so cgroups are unavailable. In Kubernetes, the container needs a writable, delegated cgroup v2 mount. Under an init such as `docker run --init`, the init shares axed's cgroup, so axed does not take it.

### Try cgroups locally

For local testing, give the container a private cgroup namespace and a writable cgroup mount. The default image runs as user 1000, which cannot write the cgroup tree, so run as root:

```sh theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
docker run -d --name axed-cg --user 0 --privileged --cgroupns=private axe --cgroups required
docker exec axed-cg axectl info | grep cgroup
```

```text theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
cgroup         /sys/fs/cgroup/
```

Then try a memory limit:

```sh theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
docker exec axed-cg axectl run --memory 32MiB -- sh -c 'x=$(yes | head -c 200000000); echo survived'
docker exec axed-cg axectl ps    # STATE oom-killed, EXIT 137
```

> [!WARNING]
>
> `--privileged` gives the container broad access to the host. Use it for local testing only, never for sandboxes that run untrusted code.

## Running as non-root

The default image runs as user 1000. Agent Sandbox pods run it with `runAsNonRoot`, all capabilities dropped and no privilege escalation. axed runs as non-root without capabilities, with these limits:

* Processes run as axed's user. Starting a process as another user (`axectl run --user`) needs the privilege to switch users.
* cgroups are usually unavailable unless the cgroup was delegated to that user.
* `axectl resumed` (`System.Configure`) steps the wall clock if it is more than 50 ms off, which needs `CAP_SYS_TIME`, then adds entropy if axed has `CAP_SYS_ADMIN` (skipped otherwise, and reported as `entropy not added`), then records the resume. Without `CAP_SYS_TIME` it fails whenever the clock is off by more than 50 ms, and then records no resume.

## Resource limits

Each process can carry its own limits, set by the client when it starts the process. With `axectl`:

```sh theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
axectl run --timeout 10m --memory 512MiB --cpus 0.5 -- make -j8
```

| Limit | With cgroups | Without cgroups |
| - | - | - |
| `--timeout` | Kills the tree after this much running time | Same |
| `--memory` (bytes, or `KiB`, `MiB`, `GiB`) | `memory.max` for the tree, swap off, `oom-killed` on breach | `RLIMIT_AS` per process |
| `--cpus` (CPUs, such as `0.5`) | `cpu.max` for the tree | Refused |

Set daemon-wide limits on axed's command line:

| Flag | Default | Bounds |
| - | - | - |
| `--retain` | `1MiB` | Output kept per process for replay |
| `--max-retain` | `64MiB` | Most output a client may ask to keep per process |
| `--output-budget` | `256MiB` | Output kept across all processes |
| `--capture-budget` | `256MiB` | Output buffered by unary executions at once, on top of `--output-budget` |
| `--max-processes` | `1024` | Processes tracked at once, running or finished |
| `--max-finished` | `256` | Finished processes kept for reattach |

axed caps client connections at half the hard descriptor limit (`ulimit -Hn`), clamped between 16 and 65,536, and splits the cap evenly among the listeners and the REST port. See the [axed reference](https://axe-engine.mintlify.site/reference/axed.md) for every flag.

Set the container's own CPU and memory limits too. They bound axed and everything it runs together.


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