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

URL: https://prized.dev/docs/sandboxes-langchain

## 1. Install the package and export your keys [#1-install-the-package-and-export-your-keys]

```bash
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](https://prized.dev/onboarding/sandboxes) and choose **Create API key** (new to Prized, it signs you up with the [free credit](https://prized.dev/docs/billing#free-credit), no card), or make one on the [API keys page](https://prized.dev/dashboard/workspace/api-keys) 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 [#2-run-an-agent]

```python title="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)
```

```bash
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](https://prized.dev/docs/billing#sandboxes)).

## Options [#options]

The common ones; the package's [page on PyPI](https://pypi.org/project/langchain-prized/) lists them all.

| Argument | Default | Effect |
| --- | --- | --- |
| `template` | `prized-base-v1` | `prized-agent-v1` adds Claude Code and Codex ([Templates](https://prized.dev/docs/sandboxes#templates)) |
| `vcpu`, `memory_mb`, `disk_gb` | The template's | The new sandbox's shape |
| `env_vars`, `labels` | None | As on a [create](https://prized.dev/docs/sandboxes-api#create) |
| `auto_pause_min`, `auto_delete_min`, `max_runtime_min` | Off, off, 1,440 | [Automatic pause and delete](https://prized.dev/docs/sandboxes#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](https://prized.dev/docs/sandboxes#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 [#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](https://prized.dev/docs/sandboxes#inside-a-sandbox)).
* **Lifetime.** 24 hours at most. On the [free tier](https://prized.dev/docs/sandboxes#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](https://prized.dev/docs/sandboxes-api#errors)); a file the agent cannot read or write comes back to it as an error instead.
