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.
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
| Behaviour | Detail |
|---|---|
| Shell | bash -c in the working directory (workdir= sets another) |
| Timeout | Default 30 minutes; a timed-out command returns exit code 124 with the output printed so far |
| Long commands | A timeout up to 80 s is one request; longer ones run as a managed process |
| Output | stdout, then stderr, cut at max_output_bytes (default 1 MiB) |
| Files | upload_files and download_files move large files in parts |
| A stopped sandbox | Started 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
OpenAI Agents SDK
Run OpenAI Agents SDK sandbox agents in Platinum microVMs, with keys held outside the VM and a stop that keeps the agent's processes.
Pydantic AI
Give a Pydantic AI agent a Platinum sandbox as its workspace, so the harness's Coder, Shell and FileSystem tools run in a microVM of their own.