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

# Branch, compare, and recover

> Run alternatives from one image, select a verified result, and recover from a known-good checkpoint.

Branching means starting independent operations from one immutable image UUID. Each branch receives new compute and its own filesystem changes.

## Compare two candidate fixes

1. Verify a baseline operation and record its result image UUID.
2. Resolve that UUID with `images.use(..., strict=True)`.
3. Start alternatives from the same object; set `disposable=False` when the changed files must be inspected or selected.
4. Compare command exit codes and deterministic artifacts. An accepted or terminal API operation alone does not establish test success.
5. Resolve the passing branch's result UUID and start a new continuation operation from it.

The fragment below shows the selection logic. It runs inside an async function with `asyncio` imported, an authenticated `client`, and a verified `baseline` image. `apply-left`, `apply-right`, and `run-tests` stand for commands supplied by the application; Sandboxes does not provide commands with those names. Use [Try two coding fixes and keep the passing branch](/sandboxes/cookbook/try-two-coding-fixes) for a complete runnable example.

```python theme={null}
left, right = await asyncio.gather(
    baseline.run(shell="apply-left && run-tests", disposable=False, timeout=120),
    baseline.run(shell="apply-right && run-tests", disposable=False, timeout=120),
)
passing = [run for run in (left, right) if run.exit_code == 0 and run.uuid is not None]
if len(passing) != 1:
    raise RuntimeError("Selection is ambiguous")
chosen = await client.images.use(passing[0].uuid, strict=True)
verification = await chosen.run(shell="run-tests", disposable=True, timeout=120)
assert verification.exit_code == 0
```

No API merges two images. A chosen branch does not continue a process from its test run.

## Recovery boundary

After a nonzero exit, platform failure, cancellation, timeout, or disconnect, keep the operation ID and safe diagnostics. Query the operation before resubmitting. Choose the next image using the [result-image rules](/sandboxes/concepts/images-checkpoints-and-branches#interpret-the-result-image).

Tags are mutable pointers. Use them for discovery and record UUIDs for reproducibility.

See [Recover from a known-good image](/sandboxes/cookbook/recover-from-known-good-image) and [Troubleshooting](/sandboxes/operate/troubleshooting).
