How do I…
How do I prepare a sandbox once and copy it?
Installing packages is the slow part. Do it once, save the sandbox's disk as a snapshot and start as many ready copies as you need – each in a few seconds.
Steps
- Create a sandbox and install everything you need.
- Save a snapshot with a name, for example
ml-ready. - Start sandboxes from the snapshot – each starts with everything installed.
- Keep the snapshot for next time, or delete it.
No code: copy this into Claude or ChatGPT with WBX Sandbox connected and change it to fit.
Create a WBX sandbox, install numpy, pandas and scikit-learn in it and save a snapshot named ml-ready. Delete that sandbox, then start two sandboxes from the snapshot and print the scikit-learn version in each.
pip install wbxsandbox, your key in WBXSANDBOX_API_KEY.
from wbxsandbox import Sandbox
base = Sandbox.create()
base.run("pip install -q numpy pandas scikit-learn", timeout=600) # slow – do it once
snap = base.snapshot(name="ml-ready") # save the disk
base.kill()
copies = [snap.create_sandbox() for _ in range(2)] # each starts ready in seconds
for i, sb in enumerate(copies):
print(sb.run(f"python -c 'import sklearn; print({i}, sklearn.__version__)'").stdout)
sb.kill()
# keep snap for next time, or: snap.delete()
npm install wbxsandbox (Node.js 20+); save as .mts for top-level await.
import { WBX } from "wbxsandbox";
const wbx = new WBX();
const base = await wbx.sandboxes.create();
await base.commands.run("pip install -q numpy pandas scikit-learn", { timeoutMs: 600_000 }); // once
const snap = await base.snapshot({ name: "ml-ready" }); // save the disk
await base.kill();
const copies = await Promise.all([0, 1].map(() => snap.createSandbox())); // ready in seconds
for (const [i, sb] of copies.entries()) {
console.log((await sb.commands.run(`python -c 'import sklearn; print(${i}, sklearn.__version__)'`)).stdout);
await sb.kill();
}
// keep snap for next time, or: await snap.delete()
Just curl and jq; your key in WBXSANDBOX_API_KEY.
H="Authorization: Bearer $WBXSANDBOX_API_KEY"
SB=$(curl -s -X POST https://sandbox.wbx.cz/v1/sandboxes -H "$H" -d '{}' | jq -r .id)
curl -s -X POST https://sandbox.wbx.cz/v1/sandboxes/$SB/exec -H "$H" -d '{"cmd": "pip install -q numpy pandas", "timeout_ms": 600000}'
SNAP=$(curl -s -X POST https://sandbox.wbx.cz/v1/sandboxes/$SB/snapshots -H "$H" -d '{"name": "ml-ready"}' | jq -r .id)
curl -s -X DELETE https://sandbox.wbx.cz/v1/sandboxes/$SB -H "$H"
curl -s -X POST https://sandbox.wbx.cz/v1/sandboxes -H "$H" -d "{\"from_snapshot\": \"$SNAP\"}" | jq -r .id # run as many times as you need
How to tell it worked
- The copies start in seconds and
import sklearnworks at once. - Next time, start from
ml-readyagain – no installing.
If it doesn't work
| What you see | What to do |
|---|---|
Only some copies start (207 or 429) | Your plan runs a set number of sandboxes at once (2 on Free). Delete the source sandbox first, as in the example. |
404 for the snapshot | It was deleted, or the ID is from a different account. |
| The copy does not have a running program | A snapshot keeps the disk. Start programs again in the copy, or use a clone. |
What it costs
Each copy is billed like any sandbox while it runs. A snapshot stays until you delete it and its size is billed as storage. Pricing.