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

# Kubernetes Agent Sandbox

> Replace sandboxd with axed in a Kubernetes Agent Sandbox template, then verify it locally with curl and grpcurl.

axed is a drop-in replacement. It uses the same flags, ports, image layout and wire formats, and the Go, Python and TypeScript SDKs work unmodified.

## Build and push the image

```sh theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
docker build -t <your registry>/axe:<tag> .
docker push <your registry>/axe:<tag>
```

The image has the same layout as sandboxd's, including the binary at `/usr/local/bin/sandboxd`. [Installation](https://axe-engine.mintlify.site/installation.md#the-default-image) lists the details.

## Change the template

Upstream's example templates use one of two topologies. Both work with only the image reference changed; they were tested on a kind cluster with upstream's Go client example and the TypeScript SDK.

> [tab] Runtime image
>
> The daemon's image is the execution environment. Replace sandboxd's image in the container spec:
>
> ```yaml theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
> containers:
>   - name: sandboxd
>     image: <your registry>/axe:<tag>    # was .../agent-sandbox/sandboxd:<tag>
>     ports:
>       - containerPort: 8080  # REST filesystem + probes
>       - containerPort: 9090  # gRPC ProcessService
>     readinessProbe:
>       httpGet:
>         path: /v1/health
>         port: 8080
> ```
>
> To add tools for the agent, build your own image `FROM` the axe image, the way upstream suggests for sandboxd's.

> [tab] Binary in an app image
>
> An init container copies the binary out of the daemon's image into a shared volume, and your unmodified app image runs it from a read-only mount, with an `emptyDir` workspace. Replace the image in the init container only:
>
> ```yaml theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
> initContainers:
>   - name: install-sandboxd
>     image: <your registry>/axe:<tag>    # was .../agent-sandbox/sandboxd:<tag>
>     command: ["/bin/sh", "-c", "cp /usr/local/bin/sandboxd /sandboxd-bin/sandboxd"]
>     volumeMounts:
>       - name: sandboxd-bin
>         mountPath: /sandboxd-bin
> containers:
>   - name: app
>     image: node:22-slim
>     command:
>       - /sandboxd-bin/sandboxd
>       - --root-dir=/workspace
>       - --rest-port=8080
>       - --grpc-port=9090
>     ports:
>       - containerPort: 8080
>       - containerPort: 9090
>     readinessProbe:
>       httpGet:
>         path: /v1/health
>         port: 8080
>     volumeMounts:
>       - name: sandboxd-bin
>         mountPath: /sandboxd-bin
>         readOnly: true
>       - name: workspace
>         mountPath: /workspace
> volumes:
>   - name: sandboxd-bin
>     emptyDir: {}
>   - name: workspace
>     emptyDir: {}
> ```
>
> `cp` follows the `/usr/local/bin/sandboxd` symlink and copies `axed` itself. The binary is static, so it runs in any app image. The read-only mount keeps sandboxed code from replacing the binary.

Everything else in the templates stays as it is: `runAsNonRoot`, `allowPrivilegeEscalation: false`, dropped capabilities, resource limits and the `emptyDir` workspace.

## Flags

axed accepts sandboxd's command line as Go parses it: every sandboxd flag with the same defaults (`--stream-chunk-size`'s default of `0` selects a larger size; see [compatibility](https://axe-engine.mintlify.site/reference/sandboxd-compatibility.md)), single-dash flags such as `-root-dir`, Go durations such as `1.5s`, and controller-runtime's `--zap-*` logging flags. Existing `command` and `args` work unchanged.

axed also has its own flags, such as `--retain`, `--output-budget` and `--cgroups`. See the [axed reference](https://axe-engine.mintlify.site/reference/axed.md) for all of them, and [sandboxd compatibility](https://axe-engine.mintlify.site/reference/sandboxd-compatibility.md) for every place axed intentionally behaves differently.

## Try it locally

Build it as `axe` (`docker build -t axe .`) and run it with the same restrictions a sandbox pod has: a non-root user, no capabilities, no privilege escalation, and a writable workspace.

```sh theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
docker run -d --name axe-pod --user 1000:1000 --cap-drop ALL --security-opt no-new-privileges \
  --tmpfs /workspace:uid=1000,gid=1000 -p 8080:8080 -p 9090:9090 axe
```

It logs two expected lines: `cgroups unavailable; using process groups and rlimits`, because a pod has no delegated cgroup, and a warning that no auth token is set.

### Files over REST

The file API is on port 8080:

```sh theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
curl localhost:8080/v1/health
curl -X PUT --data-binary 'hello' localhost:8080/v1/files/notes/hello.txt   # 204, no body
curl localhost:8080/v1/files/notes/hello.txt                                # download
curl localhost:8080/v1/files/notes                                          # list a directory
curl 'localhost:8080/v1/files/notes/hello.txt?stat=true'                    # metadata
curl -X DELETE localhost:8080/v1/files/notes/hello.txt
```

The health check returns, for example, `{"status":"ok","uptime_seconds":1}`.

### Processes over gRPC

Processes are on port 9090. axed serves gRPC reflection, so `grpcurl` needs no proto files. Reflection needs the token like any other call, so once you configure one, pass it with `-H 'authorization: Bearer <token>'`. Run it from its image; `--network host` reaches the published port on Linux and Docker Desktop.

```sh theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
docker run --rm --network host fullstorydev/grpcurl:v1.9.3 -plaintext \
  -d '{"config": {"command": ["sh", "-c", "echo hi from $(pwd)"]}}' \
  localhost:9090 process.v1.ProcessService/Execute
```

```json theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
{
  "stdout": "aGkgZnJvbSAvd29ya3NwYWNlCg=="
}
```

Output fields are base64, as gRPC's JSON mapping requires for bytes. Fields equal to zero, such as an exit code of 0, are left out.

The SDKs find their sandbox through Kubernetes, so they need a cluster, such as a local kind cluster.

Remove the container when you are done: `docker rm -f axe-pod`.

## Require a token

Mount a file holding the token, for example from a Secret, and pass `--auth-token-file`:

```yaml theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
containers:
  - name: sandboxd
    image: <your registry>/axe:<tag>
    args: ["--auth-token-file=/run/axe/token"]
    volumeMounts:
      - name: axe-token
        mountPath: /run/axe
        readOnly: true
volumes:
  - name: axe-token
    secret:
      secretName: axe-token
```

Clients then send `Authorization: Bearer <token>` or `X-Sandboxd-Token: <token>` on every call. `GET /v1/health` never needs the token, so the readiness probe keeps working. Instead of the file you can pass the token's hex SHA-256 with `--auth-token-sha256`. See [Security](https://axe-engine.mintlify.site/deploy/security.md).

## Reference

> [card] [Agent Sandbox API](https://axe-engine.mintlify.site/reference/agent-sandbox-api.md)
>
> Every REST endpoint and gRPC method the adapter serves.

> [card] [sandboxd compatibility](https://axe-engine.mintlify.site/reference/sandboxd-compatibility.md)
>
> Every intentional difference from sandboxd.


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