LangChain Deep Agents sandbox: run agent code safely in a microVM
A deepagents sandbox is a backend that runs the agent's shell commands and file edits in an isolated machine instead of on yours. LangChain Deep Agents (the deepagents package) ships three ways to do it: a state or local disk backend with no shell, a local shell backend with no isolation, and remote sandbox backends from providers such as LangSmith, Daytona, E2B, Modal, Runloop, Vercel and Lizard. For any agent that runs code it wrote itself, use a remote sandbox.
On Lizard (lizard.build), the backend is LizardSandbox from the langchain-lizard package. Lizard Sandboxes are Firecracker microVMs, each with its own kernel, and a Small one (2 vCPU, 4 GB RAM) costs $0.0162 an hour, billed per second. You need two commands to try it:
pip install langchain-lizard
lizard sandbox create -t interpreter -s small --timeout 600000 --jsonThe first installs the adapter, deepagents and the Lizard SDK. The second boots the same kind of sandbox from the Lizard CLI, so you can look around in it before an agent does. We ran the code and sandbox commands in this article on 29 November 2026 with langchain-lizard 0.1.0, deepagents 0.7.43, lizard-sdk 0.1.83 and Lizard CLI 4.0.136. The steps we did not run are marked where they appear.
What are LangChain Deep Agents?
LangChain Deep Agents is an open source agent harness: create_deep_agent() returns an agent that already has file tools, subagents and context management wired in. The Deep Agents overview describes it as a harness that "adds planning, a virtual filesystem for context, subagent spawning, and long-term memory on top of LangChain and LangGraph".
The filesystem is the part that matters here. Every Deep Agent gets ls, read_file, write_file, edit_file, delete, glob and grep, and those tools talk to a pluggable backend. With the default backend the files live in LangGraph state and nothing touches a real disk. Swap the backend and the same tools read and write a real machine.
Why does a Deep Agent need a sandbox?
A Deep Agent needs a sandbox as soon as it has the execute tool, because execute runs any shell command the model writes. Only two kinds of backend provide that tool: LocalShellBackend and the sandbox backends.
LangChain's backends page is blunt about the local option. LocalShellBackend gives the agent "unrestricted shell execution on your host", with your user's permissions, your .env files and no limit on CPU, memory or disk. The page lists production systems and untrusted input as inappropriate uses, and it notes that virtual_mode=True "provides no security with shell access enabled".
A sandbox moves that shell to a machine you can throw away. The agent loop and the model call stay in your Python process, and only the tool calls cross over. LangChain calls this the sandbox as tool pattern.
A sandbox does not stop prompt injection. The sandboxes page warns: "Never put secrets inside a sandbox." An agent that reads a poisoned web page can be told to print every environment variable and post it somewhere. Keep API keys in tools that run on your side, and treat every file that comes back as untrusted input.
Which sandbox backends does Deep Agents support?
Deep Agents supports six built-in backends and, on 29 November 2026, 31 sandbox integrations listed on LangChain's sandbox integrations page. They fall into three groups.
| Group | Backends | Shell (execute) | Isolation from your machine |
|---|---|---|---|
| Files only | StateBackend (default), StoreBackend, FilesystemBackend, ContextHubBackend, CompositeBackend | No | StateBackend and StoreBackend never touch your disk. FilesystemBackend reads and writes real files under a root directory |
| Local shell | LocalShellBackend | Yes | None. Commands run on your host |
| Remote sandbox | LangSmith, Daytona, E2B, Modal, Runloop, Vercel, Lizard and others | Yes | A separate machine at the provider |
Deep Agents has no Docker backend of its own. The backends page documents none, and the word Docker appears on the sandboxes page only for the opposite pattern, where you build an image with the agent inside it. For containers on your own hardware, the integrations page lists community packages such as KubernetesSandbox, which we did not test.
The sandboxes page shows setup code for six hosted providers: LangSmith, Daytona, E2B, Modal, Runloop and Vercel. LizardSandbox is on the integrations list with the rest. They are interchangeable from the agent's side, because a provider implements one method, execute(), and the BaseSandbox class builds the file tools on top of it by running small scripts inside the sandbox.
How do you run a Deep Agent in a Lizard sandbox with langchain-lizard?
Install langchain-lizard, create a sandbox with the Lizard SDK, wrap it in LizardSandbox and pass it to create_deep_agent(backend=...). The package needs Python 3.11 or later and pulls in deepagents 0.7.24 or newer.
First get a key scoped to one project, so a leak cannot reach anything else. (We checked lizard keys create against its --help output and did not run it; our test key was already scoped.)
pip install langchain-lizard langchain-openai
lizard keys create langchain --project <project-id>
export LIZARD_API_KEY="your-key"
export LIZARD_PROJECT_ID="your-project-id"
export OPENAI_API_KEY="your-model-key"Then the agent, adapted from the langchain-lizard README:
import os
from deepagents import create_deep_agent
from langchain_openai import ChatOpenAI
from lizard import Sandbox
from langchain_lizard import LizardSandbox
with Sandbox.create(
"interpreter",
project_id=os.environ["LIZARD_PROJECT_ID"],
timeout_ms=300_000,
size="small",
) as sandbox:
agent = create_deep_agent(
model=ChatOpenAI(model="gpt-4.1-mini"),
backend=LizardSandbox(sandbox),
)
result = agent.invoke({
"messages": [{
"role": "user",
"content": "Run Python to print the first ten Fibonacci numbers.",
}]
})
print(result["messages"][-1].content)"interpreter" is a template with Python 3 installed, which BaseSandbox needs for its file tools. size="small" pins the price, because a create that names no size is Medium ($0.0324 an hour) once you are past the trial. timeout_ms=300_000 deletes the sandbox after five minutes even if your process dies.
We did not run this script with an OpenAI model, because the test environment had no model key. We drove the same agent loop with a scripted stand-in model that returns fixed tool calls: one write_file for /work/fib.py, then one execute. The harness, the adapter and the sandbox were real. The tool messages came back as:
write_file -> Updated file /work/fib.py
execute -> [0, 1, 1, 2, 3, 5, 8, 13, 21, 34]
6.1.177+
[Command succeeded with exit code 0]The second line of the execute result is uname -r from inside the microVM: the guest's own kernel. The agent was offered nine tools: ls, read_file, write_file, edit_file, delete, glob, grep, execute and task (the subagent tool).
Across four runs, Sandbox.create() took 4.0 to 4.5 seconds to return a usable interpreter sandbox, and the first command after that took 0.08 to 0.10 seconds. Those are our own timings, taken from one machine on one day.
How do you give it files, run commands and read the results?
Your code moves files with upload_files() and download_files(), and runs commands with execute(). LangChain calls these two planes of file access: the agent's tools go through execute() inside the sandbox, while your uploads and downloads use the provider's file API.
This script seeds a CSV, runs a command and pulls the result back:
import os
from lizard import Sandbox
from langchain_lizard import LizardSandbox
with Sandbox.create(
"interpreter",
project_id=os.environ["LIZARD_PROJECT_ID"],
timeout_ms=300_000,
size="small",
) as sandbox:
backend = LizardSandbox(sandbox)
backend.upload_files([
("/work/sales.csv", b"region,amount\neu,120\nus,340\neu,80\n"),
])
result = backend.execute(
"cd /work && python -c \"import csv; "
"print(sum(int(r['amount']) for r in csv.DictReader(open('sales.csv'))))\""
" > total.txt; cat total.txt"
)
print(result.output, result.exit_code)
for f in backend.download_files(["/work/total.txt", "/work/missing.txt"]):
print(f.path, f.content, f.error)Our output:
540
0
/work/total.txt b'540\n' None
/work/missing.txt None file_not_foundA few behaviors to plan for, each seen in our runs or stated in the README:
- Paths must be absolute. Uploads create missing parent directories (
/workdid not exist before the upload). - A missing file is reported on its own entry as
file_not_found. The other files in the same call still arrive. - A failing command does not raise.
execute("ls /nope")returned exit code 2 with the error text inoutput. Stdout and stderr are joined into that one field. - Command timeouts are 1 to 600 seconds, 60 by default:
LizardSandbox(sandbox, timeout=120). Whensleep 20hit a 10-second timeout, we got exit code -1 and the text "Exec outcome unknown; do not retry with a new key" rather than a clean kill, so give long commands a generous timeout. - Each output stream is capped at 512 KiB, with a
truncatedflag on the response. Write large output to a file and download it.
Commands ran as root in a machine with 2 CPUs, 3,995 MB of memory and a 19 GB root disk, on Python 3.11.17. The Sandbox SDK reference covers the Sandbox object, and the code interpreter docs cover the template.
What does a sandboxed run cost, and how do you clean up?
A Small sandbox costs $0.0162 an hour, which is $0.00135 for a five-minute agent run and $0.0027 for ten minutes. Billing is per second from create to delete, and idle seconds count. The 20 GB disk is included in the hourly price. The model's tokens are a separate bill from your model provider.
| Run on a Small sandbox | Cost in USD |
|---|---|
| 5 minutes | $0.00135 |
| 10 minutes | $0.0027 |
| 1 hour | $0.0162 |
| 1,000 runs of 10 minutes | $2.70 |
Lizard Pro is $19 a month and includes $19 of usage, so those 1,000 runs fit inside the plan. New accounts start with a 7-day trial that needs a card and includes $5 of usage. The trial runs one Small sandbox at a time, in US regions, and deletes every sandbox one hour after it starts at the latest. Agent runs longer than an hour, or several Small sandboxes side by side, need the first Pro payment ("Start Pro now" in Billing, or lizard billing start-now, which we did not run). Pro allows 40 running vCPU, which is 20 Small sandboxes at once.
Cleanup is your job. The adapter does not own the sandbox. Three things delete it:
- The
with Sandbox.create(...)block. It kills the sandbox on exit, also when the code raises. After our runs,Sandbox.connect()to the old ID failed with "Sandbox not found". - The deadline.
timeout_msis a backstop for a crashed process. The SDK default is five minutes, andsandbox.set_timeout(ms)sets a new remaining lifetime when a session needs longer. - You, by hand:
lizard sandbox listand thenlizard sandbox rm <id>.
If you keep one sandbox per conversation thread, as LangChain's lifecycle guide suggests, store the sandbox ID with the thread, reconnect with Sandbox.connect() and set a deadline that matches how long users stay away. A paused sandbox keeps its files only, with no running processes, and its disk bills at $0.14 per GB-month while it waits.
How do the backends compare on isolation, start time and price?
The seven hosted backends in this comparison differ most in what you pay for an idle agent, and less in isolation. Five of the seven say they run each sandbox in a microVM. The table prices one hour of a 2 vCPU, 4 GB sandbox at each provider's list rate, checked on 29 November 2026. Plan fees, storage and network are not included.
| Backend | Package | Isolation, as the provider states it | 2 vCPU, 4 GB for 1 hour |
|---|---|---|---|
| Lizard | langchain-lizard | Firecracker microVM, own kernel | $0.0162 flat (Small) |
| LangSmith | langsmith | Firecracker microVM, own guest kernel | $0.189 (0.189 LSU at $1 per LSU) |
| Daytona | langchain-daytona | "Dedicated kernel"; container and VM classes | $0.1656 |
| E2B | langchain-e2b | Firecracker microVM | $0.1656 |
| Modal | langchain-modal | gVisor, or a VM runtime with its own kernel | Up to $0.238, billed on actual use |
| Runloop | langchain-runloop | Micro-VM plus container | $0.3168 |
| Vercel | langchain-vercel-sandbox | Firecracker microVM | $0.0848 idle to $0.3408 at full CPU (Pro, iad1) |
How the numbers are built: Daytona charges $0.0504 per vCPU-hour and $0.0162 per GiB-hour. E2B charges $0.000028 a second for 2 vCPU and $0.000018 a second for 4 GiB. Runloop charges $0.108 per CPU-hour and $0.0252 per GB-hour. LangSmith meters 0.0576 LSU per vCPU-hour and 0.01845 LSU per GiB-hour. Modal bills sandboxes at $0.00003942 per physical core (2 vCPU) per second and $0.00000667 per GiB per second, on the higher of what you request and what you use, so a sandbox that waits on a model costs less than the ceiling shown. Vercel bills $0.128 per hour of active CPU, which excludes time spent waiting on I/O, plus $0.0212 per GB-hour of provisioned memory.
Lizard's rate is flat: the same $0.0162 whether the agent is compiling or waiting for the model. Agents spend much of a run waiting on the model, so compare idle cost first. For what a microVM changes against a container, see What is a microVM?.
On start time we have numbers for Lizard only: 4.0 to 4.5 seconds for Sandbox.create() with the interpreter template in the runs above. We did not create sandboxes at the other six providers, so the table has no start-time column. Measure with your own template before you choose.
Lizard is the wrong pick in a few cases. LangSmith sandboxes need no second account if your traces already live in LangSmith. Modal sandboxes can attach GPUs on the gVisor runtime. Daytona also prices Windows and macOS sandboxes. If you are choosing a sandbox outside Deep Agents, Best AI agent sandboxes in 2026 compares the wider field, and Run untrusted code in Node.js and Python covers the case with no agent framework at all.
FAQ
Is deepagents the same as LangChain Deep Agents? Yes. deepagents is the name of the Python package and the GitHub repository (langchain-ai/deepagents). Deep Agents is the product name LangChain uses in its docs. You install it with pip install deepagents and call create_deep_agent().
Does Deep Agents have a Docker sandbox? No built-in one. On 29 November 2026 the built-in backends were State, Filesystem, LocalShell, Store, ContextHub and Composite, and the sandbox backends were all provider integrations. Community packages on LangChain's integrations page cover Kubernetes and self-hosted setups.
Can I use a Lizard sandbox with the deepagents CLI (dcode --sandbox)? Not with the flag today. Deep Agents Code, the terminal agent built on the same harness, has built-in providers for LangSmith, AgentCore, Daytona, Modal, Runloop and Vercel, and accepts third-party packages that publish a deepagents_code.sandbox_providers entry point, as langchain-e2b does. langchain-lizard 0.1.0 publishes no such entry point. It works through the SDK: create_deep_agent(backend=LizardSandbox(sandbox)).
Does the model run inside the sandbox? No. With a sandbox backend, the agent loop and the model request run in your Python process. Only the file tools and execute run in the sandbox, so your model API key never has to enter it.
Which Python and Deep Agents versions does langchain-lizard need? Python 3.11 or later, deepagents from 0.7.24 up to but not including 0.8, and lizard-sdk from 0.1.60 up to but not including 0.2.
Is a sandbox enough to make a Deep Agent safe? It protects your machine. Anything inside the sandbox can still leak. LangChain's docs name two gaps: context injection, and network exfiltration when outbound access is open. Keep secrets out of the sandbox and review what comes back.
How long can a Deep Agent's sandbox live on Lizard? As long as the deadline you set with timeout_ms. On the trial the limit is one hour per sandbox. After the first Pro payment a sandbox can run with no deadline, and the platform stops it at 596 hours at the latest.
Build with AI. Ship with Lizard
You don't need a platform team to go live. Your whole cloud, one CLI command away.
- Services
- —
- Add-ons
- —
- Deployments
- —
- Sandbox starts
- —