# Runs

Run evaluations and batch jobs before and after you ship. A **Run** executes a
finite program once on a dedicated GPU and gives you its logs, its result files
and its exit status. There is no cluster to keep warm: the GPU is allocated when
the Run starts and released when it ends.

```sh
nestor run evaluate.py --wait
```

```python
from nestor import Nestor

client = Nestor()
run = client.run("evaluate.py", wait=True)
print(run.state, run.failure_reason)
```

What the program does is up to you: score a model against a test set, embed a
corpus, transcode files, quantize or export a model. Nothing in it needs to
import Nestor.

## Submit

```sh
nestor run evaluate.py --wait                          # packages the file's directory
nestor run . --command 'python batch.py --shard 3' --wait
nestor run . --command 'python eval.py' --gpu A100_80G_SXM --wait
nestor run . --command 'python eval.py' \
  --input /data/test=nestor://data/dat_… --secret OPENAI_API_KEY=sec_… --wait
```

| Option | CLI | SDK | Notes |
| --- | --- | --- | --- |
| Source | path (default `.`) | `source` | A directory, or one `.py` file with its directory. Or `--source-image IMAGE@sha256:…` when the program is already in an image. |
| Command | `--command '…'` | `command=` | Runs directly, without a shell. Use `bash -lc '…'` for pipes and `&&`. |
| GPU | `--gpu FAMILY`, `--gpus N`, `--region R` | `gpu=`, `gpus=`, `region=` | Default: Auto and one GPU. |
| Environment | `--image IMAGE@sha256:…` | `image=` | Default: managed Python 3.12. |
| Inputs | `--input /data/PATH=REFERENCE` | `inputs=[…]` | [Data](/data) items or earlier run files, read-only. |
| Secrets | `--secret ENV=sec_…` | `secrets={…}` | [Secrets](/inference/keys) as environment variables. |
| Limits | `--timeout-seconds`, `--grace-seconds` | `timeout_seconds=`, `termination_grace_seconds=` | Default 24 hours (maximum 7 days) and 30 s. |
| Retry safety | `--idempotency-key KEY` | `idempotency_key=` | The same key and request returns the same Run. |

Source packaging, environments and capacity work exactly as for
[training runs](/training/runs). Every Run gets a GPU, even for steps that only
need a CPU; CPU-only Runs are not available.

## Results

Write result files under `$NESTOR_OUTPUTS`. Every regular file there when the
program stops is saved with its path, size and SHA-256 digest, including after a
failure or cancellation. Write under a temporary name and rename when complete.

```python
import json, os
from pathlib import Path

out = Path(os.environ.get("NESTOR_OUTPUTS", "outputs"))
out.mkdir(parents=True, exist_ok=True)
(out / "scores.json").write_text(json.dumps(scores))
```

```sh
nestor runs outputs tr_…
nestor runs download tr_… tf_… ./scores.json
```

Downloads verify size and digest before replacing the destination. Results are
published as [Data](/data) and stay available after the Run is deleted.

## Follow, wait and cancel

```sh
nestor runs list --state RUNNING
nestor runs logs tr_… --follow
nestor runs wait tr_… --timeout 3600
nestor runs cancel tr_…
nestor runs rerun tr_…
```

A Run moves through `QUEUED`, `PREPARING` and `RUNNING` to `SUCCEEDED`, `FAILED`
or `CANCELED`; see [Training](/training) for each state and failure reason.
`nestor run --wait` and `nestor runs wait` exit 0 when the Run succeeded, 9 for
any other final state, and 10 when the local timeout passed first. Stopping the
CLI or reaching its timeout never cancels the Run.

## Use Runs in a release process

Because exit codes are stable, a Run fits into CI: run your evaluation against a
candidate model, fail the pipeline on a non-zero exit, and keep the scores as a
downloadable result.

```sh
nestor run . --command 'python eval.py --model candidate' \
  --idempotency-key "eval-$GIT_SHA" --wait || exit 1
```

## How Runs relate to Training

A Run is a training run underneath, with the same IDs (`tr_…`), quotas and
billing. `nestor runs` and `nestor training runs` show the same jobs, and in the
Console they appear under **Training**. Not available yet: scheduled Runs,
pipelines and multi-step workflows, distributed execution, and recording an
Application on a Run (use `nestor training runs create --application`).
