Coders In Hoods
  • Courses
  • Roles
  • Blog
  • Setup

Coders In Hoods AI Academy

Every course is free. Sign in to start, and your progress, quiz scores and bookmarks follow you.

AI Academy

  • Courses
  • Paths
  • Setup guides
  • How we teach

Role roadmaps

  • AI Engineer
  • Forward Deployed Engineer
  • Machine Learning Engineer
  • All roles

Coders In Hoods

  • The agency
  • Coaching for teams
  • Blog
  • LinkedIn
  • X (Twitter)

Contact

codersinhoods@gmail.com

© Coders In Hoods · since 2019

Setup guides

Setup guide · Tools and services

Run evals with Inspect

Inspect installed in a uv project, a model configured through your own OpenRouter key or a local Ollama model, a task running in a Docker sandbox, and its log open in Inspect View.

20 min Updated 2026-11-02

Inspect is an open-source evaluation framework from the UK AI Security Institute and Meridian Labs. An evaluation is a Task made of a dataset of samples, a solver that produces an answer (one model call or a full agent), and a scorer, optionally with a sandbox per sample for tools that run code. Exercises use it to evaluate models through an API with sandboxed tools and inspectable logs. Inspect calls models through providers with an API key, not through your Claude subscription, so you'll need your own OpenRouter key or a local Ollama model. Task specs, harnesses and sandboxes compares it with Harbor and τ-bench.

Before you start

  • uv and Python 3.12 or newer (Python with uv). Inspect itself supports Python 3.11+.
  • A model: an OpenRouter key with a credit limit set on it, or Ollama running with a model that can call tools (see OpenRouter or a local model?).
  • Docker for sandboxed tasks (Docker and Docker Compose). Inspect checks for Docker Engine 24.0.6 or newer and Docker Compose 2.21.0 or newer.

1. Create a project

uv init inspect-sandbox && cd inspect-sandbox
uv add inspect-ai openai

The openai package is the client Inspect uses for both the openrouter/ and the ollama/ providers.

2. Configure a model in .env

Inspect reads a .env file from the folder you run it in (and from its parents). Create one:

.env
INSPECT_EVAL_MODEL=openrouter/anthropic/claude-haiku-5.5
OPENROUTER_API_KEY=sk-or-...

For a free local model instead:

ollama pull qwen3.5:9b
.env
INSPECT_EVAL_MODEL=ollama/qwen3.5:9b
# OLLAMA_BASE_URL=http://localhost:11434/v1   (the default)

Add .env to .gitignore before you commit anything. INSPECT_EVAL_MODEL is the default for --model. You can override it on any run with --model openrouter/anthropic/claude-sonnet-5.5 or any other provider-prefixed name.

Tip

Keep API keys in the project's .env, not your shell profile. Inspect doesn't need ANTHROPIC_* variables for OpenRouter, and exported ANTHROPIC_API_KEY or ANTHROPIC_BASE_URL would also redirect claude -p away from your subscription.

3. Write and run a first task

hello.py
from inspect_ai import Task, task
from inspect_ai.dataset import Sample
from inspect_ai.scorer import includes
from inspect_ai.solver import generate
 
 
@task
def hello():
    return Task(
        dataset=[Sample(input="Reply with the single word: ready", target="ready")],
        solver=generate(),
        scorer=includes(),
    )
uv run inspect eval hello.py

Inspect shows progress while it runs and writes a log to ./logs/.

4. Add a Docker sandbox

Tools that run commands, such as bash(), need a sandbox. Each sample gets its own container, and files copies inputs into it:

sandboxed.py
from inspect_ai import Task, task
from inspect_ai.agent import react
from inspect_ai.dataset import Sample
from inspect_ai.scorer import includes
from inspect_ai.tool import bash
 
 
@task
def find_code():
    return Task(
        dataset=[Sample(
            input="A file in the current directory contains a four-digit code. Find it and submit it.",
            target="4417",
            files={"note.txt": "The code is 4417."},
        )],
        solver=react(tools=[bash()]),
        scorer=includes(),
        sandbox="docker",
    )
uv run inspect eval sandboxed.py

With sandbox="docker" and no config files, Inspect uses its standard tool-support image, and the compose file it generates switches networking off. If you add your own compose.yaml next to the task, it replaces that generated file, so put network_mode: none in it yourself unless the task needs the network.

5. Read the logs

uv run inspect view

It serves the logs in ./logs/ on a local URL. Open a sample to see the messages, every tool call, the score and the scorer's explanation.

Options you'll use

OptionWhat it does
--model, -T key=valueThe model, and arguments to the @task function
--epochs NRun every sample N times: independent trials
--limit NRun only the first N samples
--max-connections N, --max-samples N, --max-sandboxes NConcurrent model connections, samples and containers
--message-limit, --time-limit, --working-limitPer-sample limits. Working time excludes waiting on rate limits and queues
--retry-on-error N, --no-fail-on-errorRetry samples that error, or keep going instead of failing the eval
--log-dir DIRWhere logs go (default ./logs)

Check it works

Run the first task from Python and print its status and accuracy:

uv run python -c "from inspect_ai import eval; log = eval('hello.py')[0]; print(log.status, log.results.scores[0].metrics['accuracy'].value)"

Expected output, after Inspect's progress display:

success 1.0

Troubleshooting

No API key or an authentication error. The provider's variable is missing in the folder you ran from: check that .env is in the project folder and spells OPENROUTER_API_KEY correctly. For Ollama, check that ollama serve is running and the model is pulled (ollama list).

An import error naming openai. The provider needs the openai package: uv add openai.

Docker errors when a sandboxed task starts. Make sure Docker is running, then check versions with docker version and docker compose version against the minimums above. With many samples at once on a laptop, lower --max-sandboxes.

Samples fail with rate-limit errors, or one error stops the whole eval. Lower --max-connections. Use --retry-on-error 2 for transient errors, and --no-fail-on-error to keep the other samples running, then look at the errored samples in inspect view.

Going further

  • Run agent tasks with Harbor, to run CLI agents such as Claude Code inside task containers on your subscription
  • Inspect's agent bridge runs agents such as Claude Code in a sandbox, routing their model calls through Inspect's provider
  • Noise, reproducibility and eval infrastructure, on epochs, limits, retries and what they do to a score

Sources

  • InspectDocs · UK AI Security InstituteInstallation, the Task (dataset, solver, scorer) model, the `inspect eval` and `inspect view` commands, and two complete examples.
  • Inspect: Model providersDocs · UK AI Security InstituteProvider prefixes and their environment variables, including `openrouter/` with `OPENROUTER_API_KEY` and `ollama/` with `OLLAMA_BASE_URL`.
  • Inspect: SandboxingDocs · UK AI Security InstituteDocker version requirements, per-sample sandboxes, compose files and why a custom one must set `network_mode` itself.
  • Inspect: OptionsDocs · UK AI Security InstituteEvery `inspect eval` flag, and how `.env` files and `INSPECT_EVAL_*` variables set defaults.

Exercises that use this

  • Port a Quillmoor task to Inspect and compare the logsAgent Benchmarks and Simulations · Task specs, harnesses and sandboxes

On this page

  • Before you start
  • 1. Create a project
  • 2. Configure a model in .env
  • 3. Write and run a first task
  • 4. Add a Docker sandbox
  • 5. Read the logs
  • Options you'll use
  • Check it works
  • Troubleshooting
  • Going further
  • Sources
  • Exercises that use this