Table of Contents
- Which LangChain sandbox do you need?
- How a Deep Agents sandbox works
- What a LangChain sandbox costs
- Set up a LangChain sandbox on Agent37
- Run a Deep Agent in a sandbox
- Keep one sandbox per conversation
- Block the network
- Use it from Deep Agents Code
- Five problems to avoid
- FAQ
- Is langchain-sandbox still maintained?
- Does the agent run inside the sandbox?
- Can the agent use Docker?
- How long can a sandbox run?
- Does it work with async agents?
- Which models work?
- Give your Deep Agent a sandbox
create_deep_agent as the backend. Your application keeps the agent loop and the model calls, and every execute, write_file, and grep the agent makes runs on that remote machine, away from your laptop and servers.Which LangChain sandbox do you need?
ã…¤ | What it is | Status |
langchain-sandbox | A package that ran untrusted Python in Pyodide and Deno | Archived on GitHub |
Deep Agents sandbox backends | A remote Linux machine with a shell and a filesystem, plugged into create_deep_agent | Current, with 20 providers in LangChain's docs |
LangSmith Sandboxes | LangChain's own managed sandboxes, one of those backends | Current |
How a Deep Agents sandbox works
create_deep_agent, and the agent gets an execute tool for shell commands plus its usual file tools: ls, read_file, write_file, edit_file, glob, and grep. Each tool call travels from your application to the sandbox and comes back with the output.execute(). Deep Agents' BaseSandbox builds every file tool on top of it by running small scripts inside the sandbox. Your application also gets a direct path for files: upload_files() to seed a project before the agent starts, and download_files() to collect what it built.What a LangChain sandbox costs
Provider | Per hour | 1,000 ten-minute sessions |
Agent37 | $0.0065 | $1.09 |
E2B | $0.166 | $27.60 |
Daytona | $0.166 | $27.60 |
Modal | $0.238 | $39.66 |
Runloop | $0.317 | $52.80 |
Vercel Sandbox | $0.341 | $56.80 |
Set up a LangChain sandbox on Agent37
pip install langchain-agent37 langchain-openai
export AGENT37_API_KEY=sk_live_...
export OPENAI_API_KEY=...Run a Deep Agent in a sandbox
from deepagents import create_deep_agent
from langchain_agent37 import Agent37Sandbox
with Agent37Sandbox() as sandbox:
agent = create_deep_agent(model="openai:gpt-5.5", backend=sandbox)
result = agent.invoke({
"messages": [{
"role": "user",
"content": "Write /workspace/primes.py that prints the first 10 prime numbers, run it, and tell me its exact output.",
}]
})
print(result["messages"][-1].content)write_file, then execute, and answered with 2 3 5 7 11 13 17 19 23 29. Across five creates, a new sandbox was ready in 0.56 to 1.03 seconds, and a command took a median of 0.31 seconds round trip from our laptop./workspace. The default sandbox comes with Python, Node.js, git, and common build tools, so the agent can install packages and run tests the way it would on a developer's machine.Keep one sandbox per conversation
sandbox = Agent37Sandbox(create_options={"auto_sleep": True, "idle_timeout_seconds": 900})
sandboxes[thread_id] = sandbox.id
sandbox.close() # closes the connection, keeps the sandbox and its files
with Agent37Sandbox(instance_id=sandboxes[thread_id]) as sandbox:
agent = create_deep_agent(model="openai:gpt-5.5", backend=sandbox)sandbox.destroy() when the thread ends.Block the network
with Agent37Sandbox(create_options={"network": "deny-all"}) as sandbox:
agent = create_deep_agent(model="openai:gpt-5.5", backend=sandbox)curl and pip inside that sandbox both failed to reach the internet, while commands and file writes through the backend kept working. To allow specific services, pass {"allow": [...]} with up to 100 IPv4 addresses or ranges. The network docs cover the details.Use it from Deep Agents Code
uv tool install --python 3.14 --with langchain-agent37 deepagents-code
export AGENT37_API_KEY=sk_live_...
dcode --sandbox agent37--sandbox-id <instance-id> to reconnect to a sandbox you already have.Five problems to avoid
- Each command gets a fresh shell. Files persist between commands, but
cdand exported variables don't carry over. Chain steps in one command, such ascd app && npm test, or setworkdiron the sandbox.
- Set a timeout for long jobs. A command stops after 120 seconds by default and returns exit code 124. Raise it per call, up to 840 seconds:
sandbox.execute("pytest", timeout=600). The package never retries a command, so after a network error, check whether it's still running before you send it again.
- Keep secrets out of the sandbox. LangChain's own guidance: an agent that reads a malicious instruction can read anything inside its sandbox. Keep authenticated calls in tools that run in your application, and only put values in the sandbox's
envthat you could afford to leak.
- Delete what you create. The context manager deletes a sandbox it created. A sandbox you attached to stays put when the block exits, and
close()never deletes anything. Calldestroy()when you're done.
- Custom images need three things. The file tools run as small scripts, so a custom template needs Python 3, a POSIX shell, and GNU coreutils. The default
agent37-basetemplate has all three.
FAQ
Is langchain-sandbox still maintained?
langchain-sandbox repository, which ran Python in Pyodide. New projects should use a Deep Agents sandbox backend, which gives the agent a full Linux shell.Does the agent run inside the sandbox?
Can the agent use Docker?
template="agent37-ubuntu" and create_options={"type": "vm"}. In our test, docker run hello-world worked inside the VM a few seconds after it was created, once the Docker daemon had started. A standard sandbox can't run Docker.How long can a sandbox run?
Does it work with async agents?
await agent.ainvoke(...). The async command and file methods come from Deep Agents and run in worker threads.Which models work?
Give your Deep Agent a sandbox
create_deep_agent, and your agent's commands run on a machine that costs $0.0065 an hour. The setup guide and the package README cover every option.