Sign in

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.

On this page4

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

agent.py
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.py

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

ArgumentDefaultEffect
templateprized-base-v1prized-agent-v1 adds Claude Code and Codex (Templates)
vcpu, memory_mb, disk_gbThe template'sThe new sandbox's shape
env_vars, labelsNoneAs on a create
auto_pause_min, auto_delete_min, max_runtime_minOff, off, 1,440Automatic pause and delete
timeout1800Seconds a command may run, up to 3,600
sandbox_idNoneUse 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-code with dcode install langchain-prized --package; then dcode --sandbox prized runs 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 prized can write, /tmp included. Each is written whole or not at all, and a symlink is written through to the file it points to.
  • No root. No sudo or apt (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.