What a fork is
fork_sandbox copies a sandbox as it is now, its memory, its processes and its disk, into new running sandboxes in one call, as many as its server has room for and 100 at most. Each copy goes on from the moment of the fork on its own: the same files, the same programs in the same state, a Python session with its variables, a server with its port open. Agents are copied too: a coding agent’s conversation is on the sandbox’s disk, so every copy can be prompted from where the source was.
That is what RL and eval runs need: one prepared state, many attempts from it, none of them paying again for the clone, the install or the first steps of the task.
How forking a sandbox works
The copies are made on the source’s server. A running source is copied while it runs, then pauses for a few milliseconds while its memory is captured, and goes on: 18 to 56 ms for a source whose disk was much fragmented. A paused source stays paused, and the copies of a stopped one start from its disk. Each copy is restored from reflinks of that capture, and from then on writes its own memory and disk. Measured: one copy in 258 ms through the API, three in 247 ms on the server.
A fork is all or none. When the server has no room for every copy, nothing is made and the call says how many would fit (NoCapacity), so you can ask again for that many. The copies are the source’s size, with its disk; you may give them labels of their own and other settings groups: egress, ports, environment, idle timers.
What each copy gets new, and what it keeps
Each copy has its own id, its id as its hostname, its own machine-id, and kernel randomness of its own: the kernel is reseeded at the restore. Random generators inside programs are another matter. OpenSSL’s, V8’s Math.random, Python’s random and Go’s math/rand were copied with the memory, and give the same numbers in every copy until they are reseeded; so are keys a program made before the fork. Nothing tells a process it was copied, so reseed after a fork when it matters, or ask the kernel for each random value (/dev/urandom, os.urandom, crypto/rand).
from pethost.sandboxes import Sandboxes, SandboxSettings, Size
sandboxes = Sandboxes() # reads PETHOST_TOKEN
source = sandboxes.create_sandbox("base", settings=SandboxSettings(size=Size.SMALL))
sandboxes.run_command(source.sandbox_id, command="python3 -m venv env && env/bin/pip install numpy")
# Four copies of the source as it is now: its disk, memory and processes.
copies = sandboxes.fork_sandbox(source.sandbox_id, count=4).sandboxes
for seed, copy in enumerate(copies):
command = f"env/bin/python -c 'import numpy; numpy.random.seed({seed}); print(numpy.random.rand())'"
print(copy.sandbox_id, sandboxes.run_command(copy.sandbox_id, command=command).stdout)id=$(pethost sandbox new --size small)
pethost sandbox run "$id" -- 'python3 -m venv env && env/bin/pip install numpy'
for copy in $(pethost sandbox fork "$id" --count 4); do
pethost sandbox run "$copy" -- 'env/bin/python -c "import numpy; print(numpy.random.rand())"'
doneLimits and prices
Making a copy costs nothing: each is a free start, and from its first second it is billed like any sandbox, by the second at its size’s price. Your plan bounds starts per minute, hour and day, 36, 360 and 1,200 on the $20 plan, and each copy counts as one; its vCPUs count against the plan’s budget too, 20 on the $20 plan, which holds a SMALL source and 9 SMALL copies. A fork of more copies than a window’s bound is refused outright.
A fork is refused while the source has a read-write volume mounted, and the copies always stay on the source’s server. For a state you start from again and again, over days, on any server, save a template instead: it keeps the disk, not the memory.
Short runs cost little. An eval of 1,000 SMALL sandboxes a day, 60 seconds each, is 500 sandbox-hours, $9.00 of usage a month at $0.018 an hour, inside the $20 plan; spread over the day, that is about 42 starts an hour, within its 360.
How it compares
As their pages read on 21 November 2026: E2B forks with memory too. boat.dev forks from a sandbox’s latest disk snapshot and counts each fork as a start, which costs $0.03 to $0.07 past the starts its plan includes. Vercel Sandbox’s fork copies the filesystem, and Daytona forks only its Linux VM class.