PLATINUM DOCS
SDKs

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.

Last updated

Give a Pydantic AI agent a Platinum sandbox as its workspace. Tools that use ctx.workspace, such as the Pydantic AI Harness's Coder, Shell and FileSystem, then run commands and file operations in a microVM. The model and the agent loop stay in your process.

A Pydantic AI Agent with the PlatinumSandbox capability runs in your process. Its tool calls reach the workspace, which runs commands and file operations in a Platinum microVM created on the first workspace call.

Install

The backend ships in the Python SDK as an optional extra. It needs Python 3.11 or later and pydantic-ai 2.71 or a later 2.x:

pip install 'platinum-sdk[pydantic-ai]' pydantic-ai-harness

Run an agent in a sandbox

Add PlatinumSandbox to the agent's capabilities next to the tools that use a workspace. It reads PT_TOKEN and PT_API_URL:

from pydantic_ai import Agent
from pydantic_ai_harness.coder import Coder
from platinum.pydantic_ai import PlatinumSandbox

sandbox = PlatinumSandbox(cpu=2, ram_mb=2048)
agent = Agent("anthropic:claude-sonnet-5-5", capabilities=[sandbox, Coder()])
result = await agent.run("Write hello.py and run it.")
await sandbox.destroy(result.workspace.ref)

Pydantic AI never deletes a workspace, so call destroy when the work is done.

Continue in the same sandbox

The sandbox is created on the run's first workspace operation. A later run with the message history, or with workspace=result.workspace.ref, attaches to the same sandbox and starts it if it was stopped.

BehaviourDetail
Working directory/workspace, created on first use
Long commandsA timeout up to 80 s is one request; longer ones, or none, run as a managed process
TimeoutsWorkspaceTimeoutError, with the output printed so far
CancellingA cancelled command is stopped in the sandbox
FilesThe builtin file errors (FileNotFoundError, IsADirectoryError, ...); large files move in parts

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(template="agent-tools")

Keep API keys out of the sandbox

Pass org secrets at creation. The egress proxy writes each one into its allowed hosts' request headers, so the agent's tools use the key without holding it:

sandbox = PlatinumSandbox(create_options={"secrets": ["search-api"]})

See also