> ## Documentation Index
> Fetch the complete documentation index at: https://laminar.sh/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Build the Container Image for Agent Evaluations

Each trial of an [agent evaluation](https://laminar.sh/docs/agent-evaluations/introduction.md) starts from the image that the runner declares in `eval.py`. The image holds your app and its dependencies. It is built from your current source tree, so the evals test the code you ship.

`lmnr-cli` builds the image before each run and adds the [services](https://laminar.sh/docs/agent-evaluations/services.md) to it. When nothing changed, Docker's cache is reused. You don't bump tags or push to a registry.

## Declare the image

Chain `Image`'s methods in the order the layers should be built. Each method returns a new `Image` and adds one layer. For example, this is an image for a Python app that needs a system package:

```python Example: evals/support/agent/eval.py theme={null}
from lmnr.evals import EvalRunner, Image

class SupportEval(EvalRunner):
    image = (
        Image.python("3.12")                                   # python:3.12-slim-trixie
        .apt_install("poppler-utils")                          # system packages the app needs
        .uv_sync("../../../pyproject.toml")                    # locked dependencies, not the project
        .add_dir("../../../app", "/srv/app/app")               # the code, last
        .env(APP_ENV="production")
    )
```

| Method | What it adds |
| - | - |
| `Image.python(v)`, `Image.uv_python(v)`, `Image.node(v)`, `Image.debian_slim()` | A base: Python, Python with `uv`, Node.js, or Debian. All are Debian trixie slim images. |
| `Image.from_registry(ref)` | Any image from a registry as the base, such as `"python:3.13-slim"`. |
| `uv_sync(pyproject)` | The locked dependencies from `pyproject.toml` and `uv.lock`, installed into the image's Python with `uv sync --frozen`. |
| `pip_install_from_requirements(path)`, `pip_install(...)`, `uv_pip_install(...)` | Python packages from a requirements file, or by name. |
| `npm_ci(dir, dst)` | `package.json` and the lockfile from `dir`, then `npm ci` in `dst`. |
| `pnpm_install(dir, dst)` | `package.json`, `pnpm-lock.yaml`, and `pnpm-workspace.yaml` from `dir`. Then a frozen install with the pnpm version from `packageManager`. `.npmrc` is mounted for the install only, and isn't copied into the image. |
| `apt_install(...)` | System packages. |
| `add_dir(src, dst)`, `add_file(src, dst)` | Files from your repo. |
| `run_commands(...)`, `env(...)`, `workdir(path)` | Shell commands, env vars, and the working directory. The default working directory is `/case`. Each case's `environment/` files are uploaded there. |

Databases and caches don't go in the image steps. Declare them in [`services`](https://laminar.sh/docs/agent-evaluations/services), and `lmnr-cli` installs them for you.

Some guidelines:

* **Install from the project's lockfile**, so the image has the versions production runs. Match the language version too.
* **Order the steps from rarely to often changing**: system packages, dependencies, then the code. Then a change to the app rebuilds one small layer. A `--remote` run then uploads only that layer. Services are installed before your steps, so an app change doesn't reinstall them.
* **Add specific paths from your source tree**, and nothing from `evals/`. Harness scripts reach the container through `ctx.container.run_file`. Reference answers stay in each case's `tests/` folder.

## Paths and the build context

Host paths are relative to the file that declares the step, usually `eval.py`. So `../../..` from `evals/<dataset>/agent/eval.py` is the repo root.

The build context is the deepest folder that holds all the paths the image adds. Only those paths are sent to Docker, so a large repo doesn't slow the build. `.dockerignore` in the context applies. Builds that `lmnr-cli` starts don't receive `.git` or `.env*` files.

## See what gets built

```bash theme={null}
npx lmnr-cli@latest eval describe support
```

`eval describe` prints each image's steps and services, with the file and line that declared each one. With `--json`, the output includes the whole generated Dockerfile. Each local run also keeps a copy of the Dockerfile it built in its job folder, `evals/<dataset>/jobs/<job>/<image>.Dockerfile`. For a `--remote` run, the trial's **Files** view has it under `agent/.generated/`.

## Start from a Dockerfile

Your app may already have an image definition, or need more than these steps. Then start from its Dockerfile. For example:

```python Example: evals/support/agent/eval.py theme={null}
image = Image.from_dockerfile("Dockerfile", context="../../..")
```

The path is relative to the file that calls `from_dockerfile`. `context` defaults to the Dockerfile's folder. Set it to the repo root, so the Dockerfile can copy your source. Services, and any methods you chain after it, go on top of its last stage.

```dockerfile Example: evals/support/agent/Dockerfile theme={null}
FROM python:3.12-slim-trixie
COPY requirements.txt /srv/app/
RUN pip install --no-cache-dir -r /srv/app/requirements.txt
COPY app/ /srv/app/app/
WORKDIR /case
```

* **`COPY` the specific paths you need instead of `COPY . .`** from the repo root. A broad copy would put the cases' `tests/` folders into the image, with the reference answers. The agent could read them there.
* **Services' migrations must be inside `context`**, because `lmnr-cli` copies them into the image from there. If one isn't, `eval describe` stops with a hint.
* **Build compiled binaries in a builder stage of the same Dockerfile.** A binary built on your Mac has the wrong format. The builder base's libc shouldn't be newer than the final stage's.

## Several images

Most datasets need one image. When a case needs a different system, declare named images as a dict. Then pick one in that case's `task.toml`. For example, for cases that need OCR:

```python Example: evals/support/agent/eval.py theme={null}
base = Image.python("3.12").uv_sync("../../../pyproject.toml").add_dir("../../../app", "/srv/app/app")

class SupportEval(EvalRunner):
    image = {"support-evals": base, "support-ocr": base.apt_install("tesseract-ocr")}
```

```toml Example: evals/support/tasks/scanned-invoice/task.toml theme={null}
[environment]
docker_image = "support-ocr"
```

The first image is the default, which `lmnr-cli` writes into new cases. A variant built from the same base shares its layers, so it costs one extra layer. A single image is named `<dataset folder>-evals`.

Cases can't bring an image of their own. If a case has an `environment/Dockerfile`, or a `docker_image` that the runner doesn't declare, the run stops before anything starts.

## What lmnr-cli adds to the image

On top of your steps, `lmnr-cli` adds:

* **The services.** They are copied from each vendor's official image, at the version you pinned. Each one is in a stage of its own, so changes to your app don't reinstall them.
* **The services' migrations**, in one last small layer.
* **The Laminar layer** under `/opt/lmnr`. It has its own Python with the `lmnr` package, for the runner's helpers and the mock server. It adds nothing to `PATH`, so your app's Python and Node stay as they are.

These need a Debian or Ubuntu base. See [Base image compatibility](https://laminar.sh/docs/agent-evaluations/services.md#base-image-compatibility). `--remote` runs have a few more [image requirements](https://laminar.sh/docs/agent-evaluations/running-evals.md#remote-limits-and-image-requirements).

## Next steps

> [card] [Services](https://laminar.sh/docs/agent-evaluations/services.md)
>
> Postgres, ClickHouse, Valkey, custom services, and simulated SaaS APIs.

> [card] [Write eval.py](https://laminar.sh/docs/agent-evaluations/eval-runner.md)
>
> The runner's attributes, its phases, and the `ctx` API.

> [card] [Run evals with lmnr-cli](https://laminar.sh/docs/agent-evaluations/running-evals.md)
>
> Local and remote modes, flags, CI, and sandbox limits.

> [card] [Troubleshooting](https://laminar.sh/docs/agent-evaluations/troubleshooting.md)
>
> Fixes for stale images, missing env vars, and empty traces.


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