---
title: "Run Autohand Code in Docker"
description: "Package Autohand Code into a repeatable runner image and mount repositories into the container for local or remote automation."
sidebar:
  label: "Docker"
seo:
  description: "Build a Docker image for Autohand Code and run headless repository automation with bind mounts, secrets, and repeatable container commands."
---

Intermediate · 25 min

## Provider docs used [#provider-docs]

This tutorial follows provider documentation for current Dockerfile, bind mount, and Compose secrets behavior. Keep these external guides open while you work.

**[Dockerfile overview](https://docs.docker.com/build/concepts/dockerfile/)**

docs.docker.comHow Dockerfiles define the runner image.

**[Bind mounts](https://docs.docker.com/engine/storage/bind-mounts/)**

docs.docker.comShare source code with the container.

**[Compose secrets](https://docs.docker.com/compose/how-tos/use-secrets/)**

docs.docker.comMount sensitive values into `/run/secrets` on a per-service basis.

## Step 1: Create the runner image [#step-1]

Create a Dockerfile at the root of a runner project, not inside every repository you want Autohand Code to inspect.

```dockerfile
FROM node:22-bookworm

RUN apt-get update \
  && apt-get install -y --no-install-recommends git openssh-client ca-certificates build-essential \
  && rm -rf /var/lib/apt/lists/*

RUN npm install -g autohand-cli

WORKDIR /workspace
ENTRYPOINT ["autohand"]
```

```bash
docker build -t autohand-runner:local .
```

## Step 2: Run against a local repository [#step-2]

Mount the repository into `/workspace`. Docker bind mounts can write to the host by default, so use `readonly` for review-only jobs.

```bash
cd /path/to/your-repo

docker run --rm -it \
  --mount type=bind,src="$PWD",dst=/workspace,readonly \
  -e AUTOHAND_PROVIDER=autohandai \
  -e AUTOHAND_API_KEY \
  -e AUTOHAND_AI_API_KEY="$AUTOHAND_API_KEY" \
  -e AUTOHAND_MODEL=fantail \
  autohand-runner:local \
  --bare -p "Review this repository and summarize the highest-risk issues" --restricted
```

The container has no stored Autohand sign-in, so the command passes an API key from [Autohand Console](https://console.autohand.ai/api-keys) and runs with `--bare`. Without `--bare`, the CLI waits for a browser sign-in. See [Authenticate in CI and containers](/working-with-autohand-code/headless-mode#ci-authentication).

Remove `readonly` only for trusted write jobs that need to update files in the mounted repository.

## Step 3: Keep secrets out of the image [#step-3]

Do not bake model provider keys into the Dockerfile. Pass them at runtime, or use Compose secrets for long-running runner services.

```yaml
services:
  autohand:
    image: autohand-runner:local
    working_dir: /workspace
    volumes:
      - ./your-repo:/workspace
    secrets:
      - autohand_api_key
    environment:
      AUTOHAND_PROVIDER: autohandai
      AUTOHAND_MODEL: fantail
    entrypoint: ["/bin/bash", "-lc"]
    command: >
      export AUTOHAND_API_KEY="$(cat /run/secrets/autohand_api_key)" &&
      export AUTOHAND_AI_API_KEY="$AUTOHAND_API_KEY" &&
      autohand --bare -p "Read AGENTS.md first. Review this repository and write a risk summary" --restricted --output-format stream-json

secrets:
  autohand_api_key:
    file: ./secrets/autohand_api_key.txt
```

## Step 4: Give the container Git access [#step-4]

For private repositories, mount a read-only deploy key and known hosts file. Avoid mounting your entire personal `~/.ssh` directory.

```bash
docker run --rm -it \
  --mount type=bind,src="$PWD",dst=/workspace \
  --mount type=bind,src="$HOME/.ssh/github-autohand",dst=/home/node/.ssh/id_ed25519,readonly \
  --mount type=bind,src="$HOME/.ssh/known_hosts",dst=/home/node/.ssh/known_hosts,readonly \
  -e AUTOHAND_PROVIDER=autohandai \
  -e AUTOHAND_API_KEY \
  -e AUTOHAND_AI_API_KEY="$AUTOHAND_API_KEY" \
  autohand-runner:local \
  --bare -p "Update docs for the latest CLI changes, then summarize the diff" --output-format stream-json
```

## Step 5: Use Docker on a remote host [#step-5]

When the Docker daemon is remote, bind mounts refer to paths on the remote daemon host, not your local laptop. Clone the repository on the remote host first, then run the container there. Put `AUTOHAND_PROVIDER=autohandai`, `AUTOHAND_API_KEY`, and `AUTOHAND_AI_API_KEY` in `~/.autohand/env` on the host, one `NAME=value` per line.

```bash
ssh autohand@runner.example.com
cd ~/work/your-repo

docker run --rm \
  --mount type=bind,src="$PWD",dst=/workspace \
  --env-file ~/.autohand/env \
  autohand-runner:local \
  --bare -p "Run tests and fix straightforward failures" --output-format stream-json
```

## Operations checklist [#operations]

- Keep runner images small and rebuild them when Node.js or Autohand Code changes.
- Use read-only mounts for analysis jobs.
- Mount only the Git keys needed for the job.
- Use Compose secrets or runtime environment injection, not Dockerfile `ENV`, for provider keys.
- Pin image tags in production runner scripts.
