Sign in

Run a LangChain Deep Agent in a sandbox

Updated

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 page7

A Deep Agent's shell and file tools run wherever its backend points. Pass PrizedSandbox() from langchain-prized as the backend of create_deep_agent, and they run in a Prized sandbox, a Firecracker microVM billed per second, which is deleted when its with block ends.

1. Install the package and export your keys

python3 -m venv .venv && . .venv/bin/activate
pip install langchain-prized
export PRIZED_API_KEY=dcp_…
export ANTHROPIC_API_KEY=…

The first line makes a virtual environment, since Ubuntu, Debian and Homebrew refuse pip install into the system Python (if it says ensurepip is not available, run sudo apt install python3-venv first; on Windows, run py -m venv .venv, then .venv\Scripts\activate).

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",
        system_prompt="Your files live in /home/prized/work.",
        backend=sandbox,
    )
    result = agent.invoke({"messages": [{"role": "user", "content": task}]})
    print(result["messages"][-1].text)
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 system prompt names that folder: without it, the model in this example tends to write its first file at /, gets a permission error, and tries again. 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,440 (60 on the free tier)Automatic 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. That works for a dcode from LangChain's installer or uv tool install deepagents-code; for one installed with pip, run pip install langchain-prized in its environment instead:

dcode install langchain-prized --package

Then dcode --sandbox prized runs a session in a new sandbox, and dcode --sandbox prized --sandbox-id sbx_… attaches to one that exists. With PRIZED_API_KEY exported, a new sandbox takes its settings from these variables:

VariableDefaultEffect
PRIZED_SANDBOX_TEMPLATEprized-base-v1prized-agent-v1 adds Claude Code and Codex
PRIZED_SANDBOX_VCPU, PRIZED_SANDBOX_MEMORY_MBThe template'svCPUs, and memory in MiB
PRIZED_SANDBOX_LABELSNoneLabels, as key=value,key=value
PRIZED_SANDBOX_AUTO_PAUSE_MIN15Pause after this many idle minutes, 0 for never (Automatic pause and delete); the session's next command wakes it
PRIZED_SANDBOX_VCPU=2 PRIZED_SANDBOX_MEMORY_MB=4096 PRIZED_SANDBOX_LABELS=team=evals,session=s1 dcode --sandbox prized

The same settings can live in dcode's config.toml instead, where labels add to the variable's; the page on PyPI shows how.

prized sandbox rm --label session=s1

Common questions

Which sandbox backends work with Deep Agents?

LangChain's sandboxes docs list Daytona, E2B, Modal, Runloop, Vercel, AgentCore, Databricks, NVIDIA OpenShell and LangSmith, each from its own package, and langchain-prized adds Prized, whose sandboxes also pause with their memory and fork (Options). Runloop is winding down, with support for existing customers through November 13, 2026 (Moving from Runloop).

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, a file it replaces keeps its mode (a script you made executable stays executable), and a symlink is written through to the file it points to.
  • No root. No sudo or apt (Inside a sandbox).
  • Run time. 24 hours of running by default, up to 7 days with max_runtime_min (Run time). 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.