Skip to content

Reset

A reset puts a sandbox back to the files of a snapshot. The sandbox keeps its ID, so one sandbox can start many episodes from the same state.

An episode in reinforcement learning starts from the same state each time. Without a reset, the client kills the sandbox and creates a new one from the snapshot, and the ID changes. With a reset, the client keeps one sandbox and one ID for many episodes.

from boxfork import Sandbox
with Sandbox.create("python:3.12") as env:
env.run("pip install -q numpy", check=True)
start = env.snapshot()
for episode in range(10):
env.reset(start) # the same ID, the files of the start
env.run("python3 /work/episode.py")

From the CLI:

Terminal window
boxfork reset <sandbox> <snapshot>

The HTTP API has POST /v1/sandboxes/{id}/reset. An agent has the MCP tool sandbox_reset. The snapshot can be a snapshot of a different sandbox.

Stays Goes
The ID The files outside the volumes: they become those of the snapshot
The timeout: a reset does not start it again The processes: all of them stop
The settings and the metadata The kept connection: the next command opens a new one
The volumes and the files in them
The GPUs

A command that runs at the moment of the reset fails with the code sandbox_reset. A command that arrives during the reset waits, and then runs in the new container. If the reset fails, the sandbox stays as it was. A paused sandbox is not reset: resume it first.

On the test machine, with 1 CPU and 512 MiB for each sandbox, 30 rounds each:

Operation Median
Reset, no pool 167.9 ms
Reset, from a pool of the snapshot 63.9 ms

A reset makes a new container from the snapshot, and then removes the old container before it answers. Thus no process of the old container continues after the reset. A pool of the snapshot has a container ready, so the removal is almost all of the time. A reset takes a container from a pool only when the request has no env and the sandbox has no GPU. The performance page gives all the numbers and the steps.