Skip to content

Rollouts

A rollout runs one task many ways at once:

  1. It forks a sandbox into N branches.
  2. It runs a command or script in each branch. $SVM_BRANCH_INDEX tells the branch which one it is.
  3. It scores each branch with a verifier.
  4. It keeps the branches you ask for.

Use rollouts for best-of-N agent attempts, for parameter sweeps, and for RL environments.

from svm import Sandbox, rollouts
with Sandbox.create(template="base") as sandbox:
sandbox.files.write("/tmp/attempt.py", "import random\nprint(random.choice(['pass', 'fail']))\n")
rollout = sandbox.rollout(
8,
command=["/usr/bin/python3", "/tmp/attempt.py"], # argv with an absolute path
verifier=rollouts.verify_output_match("pass"),
keep=rollouts.keep_passed(),
wait=False,
)
rollout.wait(timeout=600)
for branch in rollout.branches:
print(branch.index, branch.exit_code, branch.reward, "kept" if branch.kept else "")
for kept in rollout.kept_sandboxes():
print("kept", kept.id)
kept.kill()
Verifier Passes when
exit code the command exits with the expected code
output match the output matches a pattern
command a second command exits 0
script a shell script exits 0
Keep policy Keeps
keep passed every branch that passed
keep top k the best k
keep all, keep none everything, or nothing (the results only)

Branch sandboxes live for sandbox_timeout_seconds (default 3600). A kept branch then lives on like any other sandbox.