---
title: "Fork a running sandbox, memory and all · Pethost"
description: "Copy a running Pethost sandbox, its memory, processes and disk, into new sandboxes in one call; three copies take about 0.25 s. For RL, evals and agents."
---

[Agent Sandboxes](https://pethost.dev/sandboxes/) Fork, memory and all

# Fork a running sandbox, memory and all

Prepare an environment once, a repository cloned, its dependencies installed, a server up, an agent halfway through a task, then copy it whole, memory and processes included, and try many things from that same point.

One running sandbox at step 41 of a task is forked into three copies in 0.25 s; each carries on from step 41 on its own.

## 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`).

Python

CLI

```
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())"'
done
```

## Limits 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](https://pethost.dev/sandboxes/templates/) 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.

[Read the docs](https://pethost.dev/docs/sandboxes/forks/)

## Questions

**Can I fork a running sandbox with its memory?**

Yes: a fork copies memory, processes and disk, from a running or a paused source. A stopped sandbox has no memory to copy, so its copies start from its disk.

**Do the copies share memory with the source?**

No. Each is a sandbox of its own from the moment it is made: what one writes, the others never see.

**Are random numbers repeated in the copies?**

The kernel’s are not: it is reseeded in each copy. Generators inside programs are copied with their state, and repeat until they are reseeded.

**What does a fork cost?**

Making it costs nothing: each copy is a free start, within your plan’s starts per minute, hour and day. Each copy is then billed by the second, like any sandbox.

**Can copies land on another server?**

No: they are made on the source’s server, all of them or none.

## Related

- [A sandbox with its packages and Docker images is saved as the template my-app@3 in 1.2 s, and three new sandboxes start from it on two servers. Save a sandbox as a template Save a sandbox’s disk, packages and Docker images included, as a template version, and start new sandboxes from it on any server. How it works](https://pethost.dev/sandboxes/templates/)
- [Two lanes of seconds: a run of 37 seconds billed at $0.000005 a second, rounded up to the whole second, then paused seconds at 30%; creating it cost $0. Billed by the second Running time is billed per second at the size’s price, from $0.018 an hour; paused at 30%; stopped per GiB of data. Creating, forking and starting cost nothing. How it works](https://pethost.dev/sandboxes/per-second-billing/)

## Give your agent a computer in 0.15 s

[Start the free trial](https://console.pethost.dev/welcome?kind=sandboxes)

Pethost · Stephan Gomer · NIP 1133096755

Pethost

- [Templates](https://pethost.dev/templates/)
- [About](https://pethost.dev/about/)
- [Docs](https://pethost.dev/docs/)
- [Blog](https://pethost.dev/blog/)
- [API](https://pethost.dev/docs/api/)
- [CLI](https://pethost.dev/docs/cli/)
- [Plugin](https://github.com/pethost-dev/plugin)
- [Terms](https://pethost.dev/terms/)
- [Privacy](https://pethost.dev/privacy/)
- [Refunds](https://pethost.dev/refunds/)
- [support@pethost.dev](mailto:support@pethost.dev)

Databases

- [Postgres](https://pethost.dev/postgres/)
- [Valkey](https://pethost.dev/valkey/)

Agent Sandboxes

- [Sandboxes](https://pethost.dev/sandboxes/)
- [Pricing](https://pethost.dev/sandboxes/#pricing)
- [Docs](https://pethost.dev/docs/sandboxes/)
- [API](https://pethost.dev/docs/sandboxes/api/)

Comparisons

- [Coolify vs Dokploy vs CapRover vs Dokku](https://pethost.dev/blog/coolify-vs-dokploy-vs-caprover-vs-dokku/)
- [Coolify Cloud vs Dokploy Cloud](https://pethost.dev/blog/coolify-cloud-vs-dokploy-cloud/)
- [Railway vs Render vs Fly.io pricing](https://pethost.dev/blog/railway-vs-render-vs-fly-io-pricing/)
- [Managed Docker Compose hosting](https://pethost.dev/blog/managed-docker-compose-hosting/)

Alternatives

- [Railway alternatives](https://pethost.dev/blog/railway-alternatives/)
- [Heroku alternatives](https://pethost.dev/blog/heroku-alternatives/)
- [Dokploy alternatives](https://pethost.dev/blog/dokploy-alternatives/)
- [Coolify alternatives](https://pethost.dev/blog/coolify-alternatives/)
- [Render alternatives](https://pethost.dev/blog/render-alternatives/)
- [Sliplane alternatives](https://pethost.dev/blog/sliplane-alternatives/)
