PLATINUM DOCS
SDKs

LangChain Deep Agents

Run a LangChain Deep Agents (deepagents) agent with its file and shell tools in a Platinum microVM, through a sandbox backend in the Python SDK.

Last updated

Give a LangChain Deep Agents agent a Platinum sandbox as its backend. Its execute, ls, read_file, write_file, edit_file, glob and grep tools then run in a microVM of their own. The model and the agent loop stay in your process.

A Deep Agents agent created with create_deep_agent runs in your process with your model. Its tool calls go to the PlatinumSandbox backend, which runs the file and shell tools in a Platinum microVM.

Install

The backend ships in the Python SDK as an optional extra. It needs Python 3.11 or later and deepagents 0.7:

pip install 'platinum-sdk[deepagents]'

Run an agent in a sandbox

Create the backend and pass it to create_deep_agent. It reads PT_TOKEN and PT_API_URL, and leaving the with block deletes the sandbox:

from deepagents import create_deep_agent
from platinum.deepagents import PlatinumSandbox

with PlatinumSandbox.create(cpu=2, ram_mb=2048) as backend:
    agent = create_deep_agent(model=model, backend=backend)
    agent.invoke({"messages": [{"role": "user", "content": "Write hello.py and run it."}]})

To use a sandbox you already have, wrap it with PlatinumSandbox(sandbox=sbx) or attach by id with PlatinumSandbox.connect(sandbox_id). Neither deletes it when you are done; backend.delete_sandbox() does.

What to expect from commands

BehaviourDetail
Shellbash -c in the working directory (workdir= sets another)
TimeoutDefault 30 minutes; a timed-out command returns exit code 124 with the output printed so far
Long commandsA timeout up to 80 s is one request; longer ones run as a managed process
Outputstdout, then stderr, cut at max_output_bytes (default 1 MiB)
Filesupload_files and download_files move large files in parts
A stopped sandboxStarted again on the next call

Bring git, Node or other tools

The default template, pt-base, has Python 3.12 but no git, curl or Node. Build a template from an image once:

from platinum import Platinum, Template

Template.from_image("python:3.12-slim").apt_install(["git", "curl", "nodejs", "npm"]).build(Platinum(), "agent-tools")

The build takes a minute or two. Pass the template's name, and every new sandbox starts with those tools:

PlatinumSandbox.create(template="agent-tools")

Keep API keys out of the sandbox

Pass org secrets when you create the backend. The egress proxy writes each one into its allowed hosts' request headers, so tools the agent runs can call those APIs without ever holding the key:

with PlatinumSandbox.create(secrets=["search-api"]) as backend:
    ...

See also