---
url: /examples/your-agent-in-a-container.md
---
# Run your own agent in a container

Build a container image of an agent you wrote, and run it on a repository with one `docker run`. The agent has instructions and a skill and no MCP servers, so the image needs no configuration file, and your Anthropic API key is the only secret. You end with an image that prepares everything at build time, starts the agent offline, and prints its review of the workspace you mount. [Container images](/integrations/containers.md) explains each build step and how to cache them in layers, and [run a published agent with an MCP server in a container](/examples/agent-in-a-container.md) builds on this example.

## 1. Start from your agent project

The project is the directory that holds your agent's `pandra.toml` ([build an agent](/build.md)) and the Dockerfile you write in the next step:

```text
reviewer/
├── Dockerfile
├── instructions.md
├── pandra.toml
└── skills/
    └── review-checklist/
        └── SKILL.md
```

```toml
# pandra.toml
name = "reviewer"
version = "0.1.0"

[[instructions]]
path = "instructions.md"

[skills.review-checklist]
path = "skills/review-checklist"
```

## 2. Write the Dockerfile

The Dockerfile copies the binary from the official Pandra image, then builds and prepares the agent at build time:

```dockerfile
# Dockerfile
FROM ghcr.io/pandra-io/pandra:0.1.0 AS pandra

FROM debian:bookworm-slim
RUN apt-get update && apt-get install -y --no-install-recommends ca-certificates && rm -rf /var/lib/apt/lists/*
COPY --from=pandra /pandra /usr/local/bin/pandra
WORKDIR /agent
COPY . .
RUN pandra build --name reviewer && pandra sync reviewer --harness claude-code
ENTRYPOINT ["pandra", "run", "--offline", "reviewer"]
```

* `pandra build --name reviewer` builds the project in the current directory and stores the package under the [local name](/build/packages.md#building-a-package) `reviewer`. A package built from your own project needs no approval, so the Dockerfile has no `pandra agent trust` line.
* `pandra sync reviewer --harness claude-code` installs Claude Code and prepares the agent for it. It needs `--harness` because the image has no harness yet and no configuration that chooses one.
* `pandra run --offline reviewer` starts the prepared agent on Claude Code, the only harness installed, and fetches nothing.

If the project directory is the root of a Git repository, add `.git` to a `.dockerignore` file: a build inside a repository needs `git`, which this image does not have.

## 3. Build the image

```sh
cd reviewer
docker build -t reviewer .
```

With `--progress=plain`, which prints the output of each step, the build log shows the package and the Claude Code version that `pandra sync` installed. The sample leaves out Docker's prefix on each line and shows each digest as `<digest>`:

```text
Built reviewer 0.1.0
  Digest:  sha256:<digest>
Installed claude-code 2.1.326
Prepared reviewer 0.1.0
  Harness:    claude-code 2.1.326
  Reference:  reviewer@sha256:<digest>
  Digest:     sha256:<digest>
```

A rebuild after you change the project runs this step again and installs the newest Claude Code. To keep every rebuild on one version, pin it with `pandra harness use` ([what `pandra sync` prepares](/integrations/containers.md#what-pandra-sync-prepares)).

## 4. Run it

::: security
Claude Code reads `ANTHROPIC_API_KEY` from the container's environment, where the agent and the commands it runs can read it too. To give the key to Claude Code alone, make it a target credential, as [give the harness an API key](/examples/harness-api-key.md) does.
:::

To review a repository, run the image from the repository's directory, mount it as the workspace, pass your API key, and give the prompt. Docker adds the arguments after the image name to the entry point:

```sh
docker run --rm -v "$PWD:/work" -e ANTHROPIC_API_KEY reviewer \
    --workspace /work --prompt "Review the code in this repository." > review.md
```

Without `-t`, the container has no terminal, and the run is headless: Pandra prints only the agent's answer on stdout, which `review.md` captures, and progress and errors go to stderr. The container exits with one of Pandra's [exit codes](/automate/output.md#exit-codes).
