# Reproducible agent runs: pinning what you can, recording what you cannot

> An agent run will never replay bit for bit, because the model will not. But the environment, inputs, commands and results can be pinned or recorded, so you can explain a run, rerun its commands and compare. A design for doing that.

An agent run will never replay bit for bit, because the model will not. But the environment, inputs, commands and results can be pinned or recorded, so you can explain a run, rerun its commands and compare. A design for doing that.

November 26, 2026 · 4 min read · The Sandscale team

Someone asks why the agent’s pull request from Tuesday broke the build, and whether it would do the same today. If all you kept was the PR, you cannot answer. If you kept the right records, you can rebuild the environment the agent saw, rerun the exact commands it ran, and see which part changed.

Full reproducibility is not available: the model is not deterministic, even at temperature 0, and the outside world moves. The goal is narrower and achievable: **pin everything that can be pinned, record everything else**, so a run can be explained and its commands replayed.

## What determines a run

| Part | Can you pin it? | How |
| --- | --- | --- |
| Environment (image, tools, versions) | Yes | Template or image by digest |
| Dependencies | Yes | Lockfiles; a snapshot taken after install |
| Repository state | Yes | Commit SHA |
| Inputs (task text, files, issue body) | Record | Store them, or their hashes and a pointer |
| Model and settings | Partly | Record model ID, version, temperature, system prompt version |
| Model outputs | Record | Store each response, or at least each tool call it produced |
| Commands and results | Record | Each command, exit code, output (or its hash and size) |
| Network responses | Mostly record | Record which hosts were reached; cache or vendor where it matters |
| Time, randomness | Partly | Record start time; seed what you control |

## Pin the environment

The cheapest win is making “what machine did it run on” a single identifier.

- **Use templates pinned by digest,** not `latest`. Record the digest on the run.
- **Snapshot after setup.** If every run of a task type installs the same dependencies, take a snapshot after install and start runs from it. Record the snapshot ID. Rebuild it when the lockfile changes, and name it after the lockfile hash.
- **Record the size.** vCPU and memory change behaviour (timeouts, OOM kills, parallel test order).

```ts
// snapshots.depsFor is your own lookup from lockfile hash to snapshot ID
const box = await sandscale.sandboxes.create({
  snapshotId: snapshots.depsFor(lockfileHash),
  cpuCount: 2,
  labels: {
    task: task.id,
    repo_sha: task.commitSha,
    snapshot: snapshots.depsFor(lockfileHash),
    prompt_version: 'v14',
  },
});
```

Labels on the sandbox mean that whatever system reads the run later (your logs, the provider’s records, an audit export) carries these identifiers without a join.

## Record the conversation as tool calls

You do not need the model’s prose to replay a run’s effects. You need the sequence of tool calls it made and what each returned. Store, per step:

- the tool name and arguments (the command, the file path and content hash);
- the result your tool returned to the model (exit code, truncated output, status);
- the model ID and the hash of the full prompt for that step.

That sequence is a script. Replaying it in a fresh sandbox from the same snapshot reruns the agent’s actions without the model. If the replay gives the same results, the environment explains nothing and the difference was the model or the world. If it gives different results, something in the environment moved.

## Make commands deterministic where you can

- Set `TZ=UTC`, `LANG=C.UTF-8`, and fixed seeds for test runners that shuffle (`pytest -p no:randomly` or a fixed `--randomly-seed`; `jest --seed`).
- Use `npm ci`, not `npm install`; `pip install --require-hashes` with a locked requirements file.
- Do not let the agent fetch “latest” anything at run time; give it a registry mirror or an allowlist that includes only what the lockfile names.

## Record the network

Most nondeterminism that is not the model is the network: a package version that changed, an API that answered differently. If the sandbox network is closed by default and opened by allowlist, the list of hosts a run could reach is already a record. Add the hosts it actually reached and any it was refused. For APIs whose answers matter, record the response or its hash.

## Keep it proportional

You do not need all of this for every run. A sensible split:

- **Every run:** environment ID (template digest or snapshot), repository SHA, size, model ID, prompt version, the list of commands with exit codes.
- **Runs that produce a PR or touch real systems:** add full tool-call arguments and results, and network destinations.
- **Incident or evaluation runs:** add full model responses.

## How this fits Sandscale

Templates are pinned by digest, snapshots let new sandboxes start from a saved `/workspace`, and labels travel with each sandbox. Each command run gets a `runId`, and its output can be read back from that run’s log stream; every sandbox and API call lands in the hash-chained audit log, which Team and Enterprise can export. Sandboxes start with the network off, so the allowlist is part of the run’s definition. For replay, start a fresh sandbox from the recorded snapshot and rerun the recorded commands; our post on [structured logging for agent runs](https://sandscale.dev/blog/structured-logging-for-agent-runs) has a log schema that keeps the identifiers above together.

**On this page**

1. What determines a run
2. Pin the environment
3. Record the conversation as tool calls
4. Make commands deterministic where you can
5. Record the network
6. Keep it proportional
7. How this fits Sandscale

**Run your agents in a box of their own**

Each sandbox is a Firecracker microVM. Free includes 100 awake vCPU-hours a month.

[Start free](https://cloud.sandscale.dev/auth/signup)

## Keep reading

- [November 27, 2026 · **A LlamaIndex.TS data agent that runs its Python in a Sandscale sandbox** · Use LlamaIndex.TS's agent workflow with tools that write and run Python in a Firecracker sandbox, built per sandbox so a run can only reach its own box. Upload data files, answer with the numbers, clean up. Type-checked.](https://sandscale.dev/blog/llamaindex-ts-agent-with-sandscale)
- [November 27, 2026 · **Adding the Sandscale MCP server to Codex: config.toml, OAuth login and approval modes** · Configure the remote or local Sandscale MCP server in OpenAI Codex, sign in with codex mcp login, and use enabled_tools, approval modes and tool timeouts to match what each tool does.](https://sandscale.dev/blog/sandscale-mcp-server-in-codex)

---
Source: https://sandscale.dev/blog/reproducible-agent-runs
