English
Get started
Pethost Agent Sandboxes

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

  1. 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.

  2. Write the code and run it

    write_files puts the files in place and run_command runs any shell command. The call answers its exit code and the last 32 KiB of stdout and stderr.

  3. 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 listened
pethost 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 --terminal

Why 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_command waits 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 dev with wait_for_port 5173 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_files replaces 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.

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

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.

Start the free trial