Prerequisites
Export your Archil API key, a region where sandboxes are available (aws-us-east-1, aws-us-west-2, or aws-eu-west-1), and an AI Gateway key for the model:
Create the project
The agents’ task is to speed up a slow function without breaking its tests. Create these three files in a localproject directory: the function, its tests, and a benchmark that prints the runtime in milliseconds.
project/primes.py
project/test_primes.py
project/bench.py
Prepare the base sandbox
The base sandbox gets the project in/app, installs pytest, and commits everything to git, so you can diff each agent’s changes later. It also records a baseline benchmark.
The project lives on the sandbox’s root filesystem rather than on an Archil disk, because the root filesystem is copied into every fork. Once it’s ready, the base is stopped: it waits as a template without using compute, and forks of it boot as running sandboxes.
Fork, race, and keep the winner
The race script forks the base once per approach and runs an agent in each fork at the same time. Every agent gets the same task plus a different hint, two of them run on Claude Sonnet and one on Claude Haiku, and each has abash tool bound to its own fork.
When an agent finishes, the script scores its fork: the tests and benchmark must be untouched (git diff --quiet), the tests must pass, and the score is the benchmark time. The fastest fork wins; the others are stopped and deleted.
Clean up
A sandbox can’t be deleted while forks of it still exist; the API rejects the request withsandbox has dependent forks. Delete the winning fork first, then the base.
Next steps
Coding agent in a sandbox
Give one agent a persistent machine, run its app as a service, and pause it between sessions.
Persistent sandboxes
Lifecycle, services, network access, and forking in detail.
Branches and checkpoints
Fork an Archil disk instead of a whole machine.
Python SDK
Full reference for sandboxes, disks, and
exec options.