Run a LangChain Deep Agent in a sandbox
The langchain-prized package is a sandbox backend for LangChain Deep Agents: the agent's shell commands and file tools run in a Prized sandbox, which is deleted when the agent is done.
1. Install the package and export your keys
pip install langchain-prized
export PRIZED_API_KEY=dcp_…
export ANTHROPIC_API_KEY=…It needs Python 3.11 or later and installs Deep Agents (deepagents 0.7). For the Prized key, Open Sandboxes and choose Create API key (new to Prized, it signs you up with the free credit, no card), or make one on the API keys page with Full access, or Custom with Sandboxes: Write. The model below is Anthropic's; for another provider, install its LangChain package and change model.
2. Run an agent
from deepagents import create_deep_agent
from langchain_prized import PrizedSandbox
task = "Write fizzbuzz.py, run it for 15, and show me the output."
with PrizedSandbox() as sandbox: # creates a sandbox, and deletes it when the block ends
agent = create_deep_agent(model="anthropic:claude-sonnet-5-5", backend=sandbox)
result = agent.invoke({"messages": [{"role": "user", "content": task}]})
print(result["messages"][-1].content)python agent.pyThe agent's execute, ls, read_file, write_file, edit_file, glob and grep tools all run in the sandbox, as the user prized in /home/prized/work. The sandbox bills per second like any other (Billing: Sandboxes).
Options
The common ones; the package's page on PyPI lists them all.
| Argument | Default | Effect |
|---|---|---|
template | prized-base-v1 | prized-agent-v1 adds Claude Code and Codex (Templates) |
vcpu, memory_mb, disk_gb | The template's | The new sandbox's shape |
env_vars, labels | None | As on a create |
auto_pause_min, auto_delete_min, max_runtime_min | Off, off, 1,440 | Automatic pause and delete |
timeout | 1800 | Seconds a command may run, up to 3,600 |
sandbox_id | None | Use a sandbox that exists; it is left running at the end unless you also pass delete_on_close=True |
- Fork.
sandbox.fork(3)returns 3 running copies of the sandbox, files and processes included, each a backend for its own agent;close()deletes each (Fork). - Pause.
sandbox.pause()keeps memory and disk for the price of storage; the agent's next command wakes it. - Deep Agents Code. Install the package next to
deepagents-codewithdcode install langchain-prized --package; thendcode --sandbox prizedruns a session in a sandbox and deletes it at the end.
Limits
- Output. A command keeps the first 4 MiB of its output and of its errors; the agent is told when output was cut.
- Commands. Up to 3,600 seconds each; one that runs out of time returns exit code 124.
- Files. Up to 100 MiB each, at any absolute path the user
prizedcan write,/tmpincluded. Each is written whole or not at all, and a symlink is written through to the file it points to. - No root. No
sudoorapt(Inside a sandbox). - Lifetime. 24 hours at most. On the free tier: 60 minutes, 2 vCPU and 4 GB a sandbox, and 10 sandboxes at once.
- Keys. Code in the sandbox, the model's included, can read what you pass in
env_vars. Keep your Prized key out of it.
A refusal from the API raises PrizedAPIError, whose code is the API's (Errors); a file the agent cannot read or write comes back to it as an error instead.