A code execution sandbox for AI agents
Your model writes the code, a sandbox runs it, and the exit code and output come back in the same API call. Python, Node.js, Docker or any Linux command, in a Firecracker microVM that starts in about 0.15 s.
- A microVM per sandbox
- Starts in 0.15 s
- $0.018/h, billed per second
How to run AI-generated code in a sandbox
Make a sandbox
One call starts it in about 0.15 s from our template, Ubuntu 24.04 with Python 3, Node.js 22, build tools and Docker, or from a template you saved with your tools.
Write the code and run it
write_filesputs the files in place andrun_commandruns any shell command. The call answers its exit code and the last 32 KiB of stdout and stderr.Go on from the result
Edit a file by exact replacement, run the tests again, stream a long job’s output, or start a server and get the answer once its port listens.
from pethost.sandboxes import FileChange, Sandboxes, TextEdit
sandboxes = Sandboxes() # reads PETHOST_TOKEN
box = sandboxes.create_sandbox()
code = "x = 1\nprint(x * 42)\n"
sandboxes.write_files(box.sandbox_id,
changes=[FileChange(path="app.py", text=code)])
out = sandboxes.run_command(box.sandbox_id, command="python3 app.py",
timeout_seconds=30)
print(out.exit_code, out.stdout) # 0 42
edit = TextEdit(old_text="x = 1", new_text="x = 2")
sandboxes.write_files(box.sandbox_id,
changes=[FileChange(path="app.py", edit=edit)])
server = sandboxes.run_command(box.sandbox_id,
command="python3 -m http.server 8000",
wait_for_port=8000)
print(server.state.name) # RUNNING: answered once port 8000 listenedpethost sandbox new --name tests --size small
pethost sandbox cp ./app tests:/home/user/app
pethost sandbox run tests --cwd /home/user/app -- python3 -m unittest
pethost sandbox open tests --terminalWhy run AI code in a Pethost sandbox
A microVM per sandbox, root inside
Each sandbox is a Firecracker microVM with its own Linux kernel, kept apart from every other sandbox by its VM. The code runs as root or as a user with sudo.
The output in the same call
run_commandwaits up to 45 seconds and answers the exit code with the output. A longer job answers at once, and you stream its output as it comes.An answer when the port listens
Start
npm run devwithwait_for_port5173 and the call answers as soon as the server listens, while it runs on, ready at its preview URL.Edits that land where meant
write_filesreplaces text that occurs exactly once, in a batch made in order. An edit whose text is gone fails with the reason, as coding agents expect.Any language, Docker included
Python 3, Node.js 22 and Docker with Compose are installed, and apt installs the rest with sudo. Save it as a template to start new sandboxes with it.
Paused between calls
Idle for 5 minutes, the sandbox pauses with its files and processes at 30% of the price, and the next command wakes it in about 0.1 s where it was.
What teams build on it
A code interpreter in an AI product
Each user’s chat gets a sandbox: the model writes Python, the sandbox runs it, and the output and the files it made come back to show.
Tests for code an agent wrote
Copy the repository in, run the test suite, give the failures back to the model and run again, each run billed by the second.
App builders with a live preview
Write the app’s files, start its dev server with
wait_for_port, and show the page at its preview URL while the model goes on editing.
Limits and prices
Commands, files and terminals have no price of their own: you pay for the sandbox’s running seconds, from $0.018 an hour for SMALL (2 vCPU, 4 GiB) to $0.20 for XLARGE (16 vCPU, 32 GiB), each run rounded up to a second and 10 s at least. Idle for 5 minutes, it pauses at 30% of that. How billing by the second works.
A call waits up to 45 seconds for a command, then you read or stream the rest. A request carries 1 MiB, write_files 17 MiB, and read_file reads 1 MiB at a time; a download or upload link moves a file of any size. A sandbox serves 64 calls at once.
How it compares
On 21 November 2026, E2B charged $0.1656 an hour for a sandbox of 2 vCPU and 4 GiB, and so did Daytona; Pethost’s SMALL, the same size, costs $0.018. E2B’s sessions lasted up to 1 hour on its Hobby plan and 24 hours on Pro, Vercel Sandbox’s 45 minutes on Hobby and 24 hours on Pro. A Pethost sandbox has no limit on how long it lives.
Every sandbox, in numbers
Pethost Agent Sandboxes are cloud VMs for AI agents. Each is a Firecracker microVM with its own kernel and root inside: it starts in about 0.15 s, pauses with its memory while the agent thinks, and wakes at the next call. Billed by the second, in the EU.
- ~0.15 s to start a sandbox from a template
- ~0.1 s to wake a paused one, memory and processes as they were
- $0.018/h for 2 vCPU, 4 GiB and 10 GiB while running
- 1 s billing step: each run rounded up to a second, 10 s at least
- $0 to create or start a sandbox
Measured on our servers on 18 November 2026, through an API 16 ms away: a create’s median 123 ms (SMALL) to 158 ms (XLARGE), a resume 124 ms, a command to a paused sandbox 80 ms.
Questions
Which languages can a code execution sandbox run?
Anything that runs on Linux. Python 3 and Node.js 22 are installed, Docker runs, and apt installs the rest. Save a sandbox with your tools as a template and new sandboxes start with them.
Can I run untrusted code in it?
Yes, that is what it is for. Each sandbox is a Firecracker microVM with its own Linux kernel, kept apart from every other sandbox by its VM. An egress allow-list narrows where it may connect, and API keys kept as secrets never enter it.
How long can a command run?
As long as it needs: one call waits up to 45 seconds, then you read or stream its output. Idle for 5 minutes, a sandbox pauses with the command in memory, which goes on at the next call. A command started with keep_awake runs straight through, and so does one you follow with watch_command.
Can the code reach the internet?
Yes, over TCP: by default a sandbox may connect anywhere. An egress allow-list narrows that to the domains, IPs and ports you name. No UDP leaves a sandbox.
What if a call fails and my program retries it?
Send a request_id with the command: a retry within 24 hours runs nothing again and answers what the first call did.
How do I move large files?
Through a download or upload link, any size, or with scp over SSH.
Everything else a sandbox does
- Claude Code and Codex, installedClaude Code, Codex and OpenCode run in every sandbox with every permission: one call gives one a prompt, another streams each tool call, and your API key stays outside.
- A URL for every portA dev server on port 3000 answers at its own HTTPS address, public or behind a token, and a visit wakes a paused sandbox in about 0.2 s.
- A microVM with its own kernelEach sandbox is a Firecracker microVM with its own Linux kernel and root inside: install anything, run Docker, change any file. It starts in about 0.15 s.
- Pauses with its memoryA paused sandbox keeps its memory, processes and files at 30% of the price, and the next call wakes it in about 0.1 s, exactly where it was.
- Pauses itself when idleFive minutes without a call and a sandbox pauses, memory kept; thirty and it stops, files kept. Every timer is set per sandbox, and 0 turns it off.
- Billed by the second, starts freeRunning time by the second from $0.018 an hour, paused time at 30% of that, a stopped sandbox by the GiB of its own files. Creating and starting one cost nothing.
- A desktop with ChromeEvery sandbox has a 1280×800 screen with Chrome: click, type and screenshot in one call, drive it with Playwright or Puppeteer, or watch it live and take over.
- Plain SSH, scp and tunnelsssh, scp, sftp and ssh -L into any sandbox with a workspace key or a token as the password; a login wakes a paused one.
- Save a sandbox as a templateSet a sandbox up once and save it as a template, packages and Docker images included; start as many sandboxes as you need from it, each in about 0.22 s.
- Only the hosts you allowList the domains, IPs and ports a sandbox may reach: every other host is refused, even in DNS, and a change applies while it runs.
- API keys the sandbox never holdsCode in the sandbox sees a placeholder. Its requests still work: the real API key is put in on the way out, only to the hosts you name.
- See everything a sandbox didCPU, memory, disk and network for 24 hours, and every change of state, command, host reached and agent turn, as a list or a live stream.
Give your agent a computer in 0.15 s
From $0.018 an hour for 2 vCPU and 4 GiB, billed by the second. Paused, 30% of that. Starting one is free.