← Blog
Engineering

AI agent sandbox: what it must provide, isolation and cost per hour

Yura Dubinin
Yura Dubinin

An AI agent sandbox is an isolated computer, usually a microVM or a hardened container, where an AI agent runs shell commands, installs packages and edits files without reaching your laptop, your production servers or other users' data. An agent sandbox has to give the agent six things: a filesystem, a shell, network rules, a lifetime, snapshots and parallel copies. Hosted ones list from $0.0162 to $0.3408 an hour for 2 vCPU and 4 GB (provider pricing pages, checked on November 29, 2026).

To try one, use Lizard Sandboxes. Each sandbox is a Firecracker microVM with its own kernel, and this command starts one with Claude Code installed:

lizard sandbox create -t claude -s small

Small is 2 vCPU, 4 GB RAM and a 20 GB disk for $0.0162 an hour, billed per second. A new sandbox lives 5 minutes unless you pass --timeout.

What is an AI agent sandbox?

An AI agent sandbox is the machine an agent works on in place of yours. The model proposes an action, such as a shell command, a file edit or a script, and your application or the agent's own harness runs it inside the sandbox. If the agent deletes the wrong directory or installs a bad package, the loss is one disposable machine.

"AI sandbox" also names university and company programs for trying AI tools. This article is about the runtime that executes an agent's code.

A typical request follows this path:

  1. Your backend receives a task and asks the model to produce code or tool calls.
  2. Your backend creates a sandbox and copies in the files that task needs.
  3. The sandbox runs the code. Your backend collects stdout, stderr, files, and the exit code.
  4. Your backend checks the result before showing it to the user or sending it to another service.
  5. Your backend saves the required output and deletes the sandbox.

A coding agent such as Claude Code or Codex can also run inside the sandbox itself. Then steps 2 to 4 happen in one place, and your backend sends a prompt and reads the result.

Keep the model provider key and the sandbox management key in your backend. Giving generated code a management key would let it request more resources using your account.

What must an agent sandbox give an agent?

An agent sandbox must give the agent a filesystem, a shell, network rules, a lifetime, snapshots and parallel copies. We ran every Lizard command in this section on November 29, 2026 with Lizard CLI 4.0.136, in Small sandboxes in us-east-1 that we deleted afterwards.

A filesystem of its own

The agent needs a disk where it can clone a repository, install dependencies and write build output, and that disk must not be yours. In our Small sandbox, df -h / showed a 19 GB root filesystem with 1.5 GB used by the claude template, nproc printed 2 and free -m showed 3,995 MB of memory.

Copy in only what the task needs. Whatever you put on that disk, the agent can read.

A shell

Agents work through commands, so the sandbox must run a command and return stdout, stderr and the exit code.

lizard sandbox exec <id> -- python3 --version
lizard sandbox exec <id> -- claude --version

In the claude template these printed Python 3.11.2 and 2.1.286 (Claude Code). Commands ran as root. That is acceptable inside a disposable microVM and unacceptable on a laptop.

Network rules

An agent that can read a secret and open any connection can send that secret anywhere. A sandbox needs a way to close the network or limit it to named hosts.

lizard sandbox create -t base -s small --allow-host pypi.org --allow-host '*.pythonhosted.org'

--allow-host implies --no-internet, and the rule holds for the sandbox's whole life. In our test, curl https://example.com failed inside that sandbox, curl https://pypi.org/simple/requests/ returned 200, and pip install idna worked.

Check this control on any provider before you rely on it. Isolation from the host does not mean outbound traffic is blocked.

A lifetime

A sandbox needs a deadline enforced by the platform. A timeout in your client stops the waiting and can leave the remote machine running and billing.

Lizard CLI and Lizard SDK give a new sandbox 5 minutes. --timeout 20m sets another deadline at create, and lizard sandbox timeout <id> 1800000 moves it later; in our test the second command returned a new expiry 30 minutes ahead. On a paid plan a sandbox with no deadline stops after 596 hours at most. On the 7-day trial every sandbox is deleted 1 hour after it starts.

Snapshots and pause

A long task needs a point to return to. A snapshot saves the sandbox's files, and a pause stops compute billing while keeping them.

lizard sandbox snapshot <id> --name before-refactor
lizard sandbox restore <snapshot-id>
lizard sandbox pause <id>
lizard sandbox resume <id>

On Lizard, a snapshot and a pause keep files only. We wrote a file and started a background sleep process, then paused and resumed. The file was there after the resume, the process was gone, and the machine had booted fresh. The sandbox restored from the snapshot had the file too. A paused sandbox has no compute charge; its used disk, like each snapshot, costs $0.14 per GB-month (pricing).

Providers differ here. E2B, for one, keeps memory and files across a pause, so check what yours keeps before an agent depends on a running process.

Parallel copies

Several agents on one task each need the same starting state: one repository, with dependencies already installed.

lizard sandbox fork <id> -n 3

A fork on Lizard starts a new sandbox from a copy of the source's files. It boots fresh, with no memory or processes carried over, and the source keeps running. We forked three copies in the test. Each had our file, none had the sleep process, and the source still did. The three forks returned in 1.7 seconds, measured once from our machine. Lizard Pro runs 40 vCPU at once, which is 20 Small sandboxes.

Containers, gVisor or Firecracker microVMs: which isolation does an agent sandbox need?

For code an agent wrote and nobody reviewed, pick a boundary with its own kernel: a microVM, or gVisor's userspace kernel. A standard container fits code you already trust.

ApproachWhere the boundary sitsWhat to check
Standard Docker containerLinux namespaces and resource controls separate processes, and every container uses the host's kernel.Capabilities, privileged mode, host mounts, daemon access, and host patching.
gVisorA userspace application kernel handles application system calls, reducing direct exposure to the host kernel.System call compatibility and performance for your workload.
Firecracker microVMA virtual machine has its own guest kernel and uses KVM for hardware virtualization.Guest and host patching, network policy, mounted data, and lifecycle controls.

Docker can suit workloads with a known trust level and a carefully configured host. Its security depends on how you run it; exposing the Docker socket or broad host mounts changes what the workload can control. See Docker's security documentation.

gVisor adds a userspace kernel boundary, with compatibility tradeoffs. Firecracker uses a small virtual machine monitor and a limited device model. Neither removes the need to protect secrets or restrict access to sensitive services.

Lizard Sandboxes run as Firecracker microVMs, each with its own kernel. See the Lizard Sandboxes documentation, and what a microVM is for how the boundary works.

What does an agent sandbox not protect?

A sandbox limits where code runs. It does not decide which secrets, users and outputs your application trusts.

Credentials and network access

Anything you copy into the sandbox becomes available to the workload under the permissions you give it. Avoid copying your whole .env, SSH directory, or cloud credentials. If a task needs an external API, give it a short-lived credential with narrow permissions, or route the operation through a backend tool that checks each request.

Users and stored files

Assign each sandbox to an authenticated user or job. Check ownership on every request to execute code, download a file, or reopen a session. A guessed sandbox ID must not grant access.

Keep persisted files separate by user too. Reusing a writable workspace across unrelated customers can expose data even when each execution gets a fresh virtual machine.

Returned output

Treat returned files and text as untrusted input. Validate JSON against the shape your application expects. Escape text when rendering it, and avoid serving generated HTML on the same origin as your account dashboard.

For agents that skip interactive approvals, these controls matter before the first command runs. Our Claude Code permission guide covers that workflow.

Should an agent sandbox run locally or in the cloud?

Run the sandbox locally when one developer runs one agent on their own machine. Move to the cloud when you need several agents at once, runs that continue after the laptop closes, or sandboxes for your own users.

Two local options cover most cases:

  • Claude Code has a built-in sandbox for its Bash tool, turned on with /sandbox. It uses Seatbelt on macOS and bubblewrap on Linux and WSL2 to restrict files and network hosts (Claude Code docs). The commands still run on your machine and on its kernel.
  • Docker Sandboxes run each agent in a microVM on your machine, managed with the sbx CLI (Docker docs). Our Docker Sandboxes guide covers setup and limits.

A local sandbox uses your CPU, memory and battery, and it stops when the laptop sleeps. A cloud sandbox is created through an API and billed by the second, and it runs until its deadline whether or not you are connected. That is what a product needs when each user's agent gets its own machine.

Claude Code sandbox: /sandbox, Docker or a cloud VM compares the three setups for one agent, and Codex sandbox does the same for Codex.

How do you run an agent in a cloud sandbox?

Create the sandbox, send the agent a prompt, read the result and delete the sandbox. On Lizard that is four commands:

lizard sandbox create -t claude -s small --timeout 20m
lizard sandbox prompt <id> --agent claude "Write /home/user/sum.py that prints the sum of 12, 8 and 5, run it with python3, and tell me the output."
lizard sandbox exec <id> -- python3 /home/user/sum.py
lizard sandbox rm <id>

In our run on November 29, 2026, the create returned a running Small sandbox in 1.3 seconds, measured once. The agent made two tool calls, wrote the file and answered that the output is 25, and the exec printed 25. We sent the prompt through the same API that lizard sandbox prompt calls and checked the CLI flags with --help. Pass --agent claude, because the command's default agent is Codex.

The agent runs on the Claude sign-in connected to the sandbox's project, so connect it in that project first. On the 7-day trial (card required, $5 of usage) you can run 1 Small, 2 Mini and 2 Nano sandboxes at a time, in US regions only, and each is deleted after 1 hour. A fork counts as one more sandbox of its source's size. Long runs and parallel forks of a Small therefore need Lizard Pro, which is $19 a month with $19 of usage included (limits).

How do you call a sandbox from your own backend?

Use Lizard SDK when your application creates the sandbox. This example uses Node.js as the backend controller and Python inside the sandbox. It runs a fixed calculation so you can check the execution path before adding a model. It does not call an LLM.

Use Node.js 22 or later, a Lizard project, and a Lizard API key. Set LIZARD_API_KEY and LIZARD_PROJECT_ID in your backend environment. Keep both out of browser code; the API key belongs in your secret store.

Install the JavaScript client:

npm install @lizard-build/sdk@1.0.24

Save this as run-task.mjs:

import { Lizard } from "@lizard-build/sdk";

const project = process.env.LIZARD_PROJECT_ID;
if (!project || !process.env.LIZARD_API_KEY) {
  throw new Error("Set LIZARD_PROJECT_ID and LIZARD_API_KEY");
}

const lizard = new Lizard({ project });
const sandbox = await lizard.create("base", {
  size: "small",
  timeoutMs: 120_000,
});

try {
  const script = [
    "import json",
    "values = [12, 8, 5]",
    "print(json.dumps({'total': sum(values)}))",
  ].join("\n");

  await sandbox.fs.write("/tmp/task.py", script);
  const result = await sandbox.process.exec(
    ["python3", "/tmp/task.py"],
    { user: "user", timeoutMs: 30_000 },
  );

  if (result.exitCode !== 0 || result.truncated) {
    throw new Error("Task failed or returned incomplete output");
  }
  if (Buffer.byteLength(result.stdout, "utf8") > 4096) {
    throw new Error("Task output exceeds the application limit");
  }

  const output = JSON.parse(result.stdout);
  if (
    output === null ||
    typeof output !== "object" ||
    Array.isArray(output) ||
    Object.keys(output).length !== 1 ||
    output.total !== 25
  ) {
    throw new Error("Unexpected task output");
  }

  console.log(output);
} finally {
  await sandbox.kill();
}

Run it from your backend machine:

node run-task.mjs

On November 29, 2026, we ran this exact script with Node.js 22.23.2 and Lizard SDK 1.0.24. It created a Small Firecracker sandbox from the base template, ran Python as user, printed { total: 25 }, and completed cleanup with exit code 0 in about 4 seconds.

The SDK reads LIZARD_API_KEY from the controller's environment. This code does not pass it into the sandbox that executes Python.

The argument array executes Python without shell interpolation. Python can still perform whatever operations the sandbox allows. The 30-second command timeout limits how long the client waits; the two-minute sandbox lifetime sets a separate expiry. The finally block requests cleanup even if output validation fails. See the Lizard SDK reference.

To turn this into an agent tool, replace the fixed script with the code your model returns and define a result schema for that task. Keep authorization, resource limits, and output checks in the backend. A successful exit code alone does not prove that the answer is correct.

What does an AI agent sandbox cost per hour?

A hosted agent sandbox with 2 vCPU and 4 GB lists from $0.0162 to $0.3408 an hour, before plan fees. Each price below comes from the provider's own pricing page, checked on November 29, 2026.

Provider2 vCPU / 4 GB per hourHow the page prices it
Lizard Sandboxes$0.0162Small, one hourly price, billed per second while running
E2B$0.1656$0.000028 a second for 2 vCPU plus $0.000018 a second for 4 GiB
Daytona$0.1656$0.0504 per vCPU-hour plus $0.0162 per GiB-hour
Modal Sandboxes$0.238$0.00003942 per core-second (one core is 2 vCPU) plus $0.00000667 per GiB-second, on the higher of requested and used
Vercel Sandbox$0.3408 at 100% CPU$0.128 per Active CPU hour plus $0.0212 per GB-hour of provisioned memory (iad1)

The models differ, so the same sandbox can cost less than its row. Vercel charges CPU only while code uses it: a 2 vCPU / 4 GB sandbox that sits idle costs $0.0848 an hour for memory alone. Modal bills the higher of what you request and what you use. Lizard, E2B and Daytona bill the allocated size for every running second, idle time included.

Plan fees, included usage and limits on parallel sandboxes change the monthly total. Best AI agent sandboxes in 2026 lists them for 12 providers, and the sandbox pricing calculator compares the hourly rates for your own sizes and hours.

Lizard's sizes, from its pricing page:

SizevCPURAMDiskCompute per hour
Small24 GB20 GB$0.0162
Medium48 GB40 GB$0.0324
Large816 GB80 GB$0.0648

Lizard meters compute per second while a sandbox runs, including idle time. A create that names no size is Medium on a paid plan, so pass -s small (CLI) or size: "small" (SDK) to get the Small price. Lizard Pro costs $19 per month and includes $19 of usage; usage above that is pay as you go.

For 1,000 Small jobs that each keep a sandbox running for five minutes:

1,000 × (5 / 60 hours) × $0.0162 = $1.35 in compute usage

The same 83.3 sandbox-hours cost $13.80 at $0.1656 an hour. Both figures are compute only: plan fees, storage and model tokens are separate.

If those jobs each leave a sandbox running for an extra hour, they add $16.20 in compute usage on Lizard. An explicit lifetime and reliable cleanup can matter more than a small difference in hourly rates.

How do you choose an AI agent sandbox?

Choose by the job your agent does, then test with that job. A quick shell command tells you little about a repository build or a browser session.

Record startup time, dependency installation time, total task time, failures, and total running seconds. Check the slowest requests as well as the median. Our E2B, Daytona, and Modal comparison gives a starting point for comparing execution workflows.

Before adopting a runtime, answer these questions:

  • What separates one customer's code and files from another's: a container, gVisor or a microVM?
  • Which secrets and external services can generated code reach, and can you close the network?
  • Can the runtime run the languages, packages, and browser tools the task needs?
  • What happens when the controller crashes or loses its connection? Does the platform enforce a deadline?
  • Which files survive a pause or a snapshot, and does memory survive?
  • How many sandboxes can run at once on your plan?
  • What will the full workload cost with idle time, storage, and model calls?

For the providers themselves, with prices, session limits and a pick for each job, read Best AI agent sandboxes in 2026: 12 providers compared.

For a first implementation, start with one task, one temporary sandbox, and a small validated result. Create it with lizard sandbox create -t claude -s small, measure that flow, then add snapshots, forks or longer sessions when the application needs them.

Sandbox guides by topic

Coding agents

Prices and providers

Isolation and untrusted code

Building on sandboxes

Build with AI. Ship with Lizard

You don't need a platform team to go live. Your whole cloud, one CLI command away.

Start 7-day trial
Services
—
Add-ons
—
Deployments
—
Sandbox starts
—

We use cookies for essential site functionality and analytics. See our Cookie Policy.