platinum-sdk (Python)
Python client for Platinum — hardware-isolated sandbox microVMs (one Cloud Hypervisor VM per sandbox, sub-second boots via a warm pool). Docs: platinum.dev/docs/sdk/python.
pip install platinum-sdk # import name: platinum
Python ≥ 3.9, typed (PEP 561 — ships py.typed; mypy --strict clean). Sync and async clients. Server-side use only — never ship an API key into client-side code.
Quickstart
from platinum import Platinum
dn = Platinum(token="pt_live_...", api_url="https://api.platinum.dev")
# or: PT_TOKEN / PT_API_URL env vars
# Pick a template that exists on YOUR deployment first:
print(dn.templates.list())
sbx = dn.sandboxes.create(template="pt-base", wait_for_running=True)
r = sbx.exec(["uname", "-a"]).check() # .check() raises on non-zero exit
print(r.stdout)
sbx.delete()
Async — a full 1:1 mirror of the sync surface:
from platinum import AsyncPlatinum
async with AsyncPlatinum(token="pt_live_...", api_url="https://api.platinum.dev") as dn:
sbx = await dn.sandboxes.create(template="pt-base", wait_for_running=True)
r = await sbx.exec("uname -a") # argv list or plain string
print(r.stdout)
await sbx.delete()
Expose a port at create time (URL comes back in the same response):
sbx = dn.sandboxes.create(
template="pt-base",
expose=[{"port": 8080, "public": True}],
wait_for_running=True,
)
print(sbx.exposed_url(8080))
Build a custom image inline (cache-hit on repeat, built on first use):
from platinum import Platinum, Template
dn = Platinum()
image = (Template.from_python_image("3.12-slim")
.pip_install(["fastapi", "uvicorn"])
.workdir("/app"))
sbx = dn.sandboxes.create(image=image, wait_for_running=True, wait_timeout_ms=600_000)
Configuration
| Arg / env | Default | Meaning |
|---|---|---|
token / PT_TOKEN |
— (required) | API key pt_live_…, org-scoped bearer token |
api_url / PT_API_URL |
https://api.platinum.dev |
Control-plane URL (PLATINUM_API_URL also works) |
timeout |
60.0 |
Per-request timeout in seconds (file transfer calls override per call) |
transport |
— | httpx transport override (e.g. httpx.MockTransport in tests) |
Errors
Everything the SDK raises extends PlatinumError (.status, .body, .code — the
API's machine-readable error code, also folded into str(err)):
from platinum import NotFoundError, ConflictError, RateLimitError
try:
sbx.exec("true")
except NotFoundError: # sandbox gone
...
except ConflictError as e: # e.g. e.code == "sandbox_not_running"
...
except RateLimitError as e: # still limited after the client's retries: back off e.retry_after_seconds
...
Subclasses: ValidationError (400) · AuthenticationError (401) · ForbiddenError (403)
· NotFoundError (404) · ConflictError (409) · RateLimitError (429) · ServerError
(5xx) · PlatinumTimeoutError / PlatinumConnectionError (client-side, status == 0).
Retries: a request the server refused before doing any work (429, 503, or an answer marked retryable) is retried up to retries times (default 3, 0 disables) with exponential backoff, within the request's timeout. 502/504 and dropped connections are retried only for GET, HEAD, OPTIONS and DELETE; a streamed body is sent once.
Surface (at parity with the TypeScript SDK)
The two SDKs expose the same operations — enforced in CI by verify/sdk-parity.sh
(name-level) and the offline unit suites (behaviour). The async client mirrors the sync
surface 1:1 (enforced by tests/test_unit.py::test_async_mirrors_sync_surface).
| Area | Methods |
|---|---|
| Sandboxes | sandboxes.create(...) · get · connect · list · iter (auto-pagination) · rename · delete |
| Lifecycle | stop/start (optional server-side wait) · pause/resume · kill · resize · fork · clone · snapshot · list_snapshots · delete_snapshot · restore · restore_from_backup · archive · backup · wait_running · wait_state · refresh |
| Run | exec(argv | str) · sh(script) · run_code(code, lang=None) — defaults to the sandbox's create-time language |
| Processes | process.start(cmd, cwd=, env=, pty=, cols=, rows=, timeout_ms=) · process.list() · process.get(handle) — the handle has logs · stream · stdin/close_stdin · signal · kill · resize · wait · refresh |
| Files (vsock) | files.read/write/delete/list/stat/mkdir/exists · find (glob) · grep (content) · replace (bulk sed) · watch (generator of change events) |
| Networking | expose(port, public=, ttl_seconds=) · unexpose · exposed_url · revoke_expose_token · set_egress_policy · add_ssh_keys |
| Observability | metrics() (live cpu/mem/disk) · usage() (billed usage) · events(limit=, before=) (failed starts, retries, disk pressure) |
| Browsers | browsers.create/list/get/pause/resume/delete · cdp_url(id, ttl_seconds=, rotate=) — connect Playwright or Puppeteer to the cdp_url (a credential) |
| Volumes | volumes.create/get/list/open/delete/rename · per volume: fork · tag/tags/untag · history · restore · diff |
| Secrets | secrets.create/list/get/update/rotate/delete/bind/unbind — the egress proxy spends them for a sandbox; the sandbox never sees the value |
| Platform | templates.list/get/delete · Template builder · webhooks.* · regions.list() · me() · health.check() |
| Results | ExecResult(stdout, stderr, exit_code, duration_ms, lang) with .check() |
Run something that outlives the call — exec kills its process group the moment it
returns, process.start does not:
p = sbx.process.start(["python", "-m", "http.server", "8000"], cwd="/workspace")
print(p.handle, p.pid)
for chunk in p.stream(): # resumes at the last byte if the socket drops
if chunk.type in ("stdout", "stderr"):
if chunk.dropped: # the ring buffer evicted bytes — a HOLE, not a stat
print(f"[{chunk.dropped} bytes lost]")
print(chunk.data, end="") # str, decoded here — a split emoji arrives whole
elif chunk.type == "reconnect": # incl. the server's 30-min cap: it keeps going
print(f"[resumed at {chunk.stdout_offset}: {chunk.reason}]")
elif chunk.type == "exit": # the only terminal event — the loop ends here
print("exit", chunk.exit_code)
p.signal("SIGTERM") # or p.kill() — the record (logs + exit code) is kept
Reconnect to it later from anywhere — reads are by absolute byte offset, so nothing is replayed and nothing is lost:
p = sbx.process.get(handle)
out = p.logs(stdout_offset=my_last_offset)
print(out.stdout, out.stdout_offset, out.running, out.exit_code)
raw = p.logs(encoding="base64").stdout # bytes, not str — binary-safe
Interactive PTY (stdin also delivers control characters), and a server-side wait:
sh = sbx.process.start("bash -i", pty=True, cols=120, rows=40)
sh.stdin("ls -la\n")
sh.resize(100, 30)
sh.stdin(b"\x03") # ^C
done = sbx.process.start(["make", "build"]).wait(timeout_ms=600_000)
print(done.exit_code)
Async is the same surface with await / async for (await sbx.process.start(...),
async for chunk in p.stream()). Managed processes need an in-VM agent that implements
them; an older guest answers 409 managed_procs_unsupported and exec still works.
Watch for file changes:
for ev in sbx.files.watch("/workspace", max_seconds=60):
if ev["event"] == "change":
print(ev["data"]["type"], ev["data"]["path"])
Not wrapped yet: interactive terminal (WebSocket), cross-host migrate (admin-only),
API-key management, audit-log queries, billing.
OpenAI Agents SDK
platinum.openai_agents is a sandbox provider for the OpenAI Agents SDK
(openai-agents 0.25.x, Python 3.10+). SandboxAgents then run their shell,
file and patch tools in a Platinum microVM:
pip install 'platinum-sdk[openai-agents]'
from agents import RunConfig, Runner
from agents.sandbox import SandboxAgent, SandboxRunConfig
from platinum.openai_agents import PlatinumSandboxClient, PlatinumSandboxClientOptions
client = PlatinumSandboxClient() # PT_TOKEN / PT_API_URL
agent = SandboxAgent(name="dev", instructions="Work in the sandbox.")
result = await Runner.run(agent, "Write hello.py and run it.", run_config=RunConfig(
sandbox=SandboxRunConfig(client=client, options=PlatinumSandboxClientOptions(cpu=2, ram_mb=2048)),
))
Supported: exec (timeouts above 80 s, and no timeout, run as managed processes),
file read/write, tar persist_workspace/hydrate_workspace, PTY sessions
(exec_command + write_stdin), exposed ports (preview URLs), and resume
of a stopped sandbox (pause_on_exit=True stops instead of deleting, keeping
memory and processes). Not supported: cloud bucket mounts, and native snapshot
persistence. import platinum does not import openai-agents.
LangChain Deep Agents
platinum.deepagents is a sandbox backend for LangChain Deep Agents
(deepagents 0.7.x, Python 3.11+). The agent's execute, ls, read_file,
write_file, edit_file, glob and grep tools then run in a Platinum microVM:
pip install 'platinum-sdk[deepagents]'
from deepagents import create_deep_agent
from platinum.deepagents import PlatinumSandbox
with PlatinumSandbox.create(cpu=2, ram_mb=2048) as backend: # PT_TOKEN / PT_API_URL; deleted on exit
agent = create_deep_agent(model=model, backend=backend)
agent.invoke({"messages": [{"role": "user", "content": "Write hello.py and run it."}]})
PlatinumSandbox(sandbox=sbx) wraps a Sandbox you already have, and
PlatinumSandbox.connect(sandbox_id) attaches to one by id; neither deletes it
(backend.delete_sandbox() does). Commands run with bash -c in the template's
working directory (workdir= sets another). Without a timeout a command may run
timeout seconds (default 30 minutes); a timeout up to 80 s is one exec request,
a longer one or timeout=0 runs as a managed process. A timed-out command
returns exit code 124 with the output it printed. Output is stdout then stderr,
cut at max_output_bytes (default 1 MiB). Deep Agents' own file operations
always take the one-request path and are not cut. upload_files/download_files
use the filesystem API and move large files in parts. A stopped sandbox is
started again on the next call. import platinum does not import deepagents.
Pydantic AI
platinum.pydantic_ai is a workspace for Pydantic AI (pydantic-ai 2.71 or later 2.x,
Python 3.11+): PlatinumSandbox is a capability that supplies a Platinum
sandbox as the run's workspace, and PlatinumSandboxBackend implements the
WorkspaceBackend protocol (SupportsCommands, SupportsFilesystem,
SupportsRealpath). Tools that use ctx.workspace, such as the Pydantic AI
Harness's Coder, Shell and FileSystem, then run in a Platinum microVM:
pip install 'platinum-sdk[pydantic-ai]' pydantic-ai-harness
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) # PT_TOKEN / PT_API_URL
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
The sandbox (pydantic-ai-<random>, pt-base unless template=) is created
on the run's first workspace operation. A later run with the message history,
or workspace=result.workspace.ref, attaches to it, starting it if it was
stopped; a deleted one raises WorkspaceUnavailableError. Commands start in
working_dir (/workspace, created on first use) with stdin at EOF; a
timeout up to 80 s is one exec request, a longer one or none a managed
process, and a cancelled command is stopped. A timeout raises
WorkspaceTimeoutError with the output so far. File operations use the
filesystem API and raise the builtin file errors; large files move in parts.
env= is set on the sandbox; for API keys use create_options={"secrets": [...]}, which the sandbox spends without holding them. The SDK is asyncio
only, so the backend refuses Trio. import platinum does not import
pydantic_ai.
Google ADK
platinum.adk gives a Google Agent Development Kit agent (google-adk 2.14 or
later 2.x, Python 3.11+) tools that run in a Platinum microVM. PlatinumPlugin
is an ADK plugin, shaped like the Daytona plugin: get_tools() returns
execute_command_in_platinum, execute_code_in_platinum (Python),
write_file_to_platinum, read_file_from_platinum, list_files_in_platinum
and delete_platinum_sandbox, all on one sandbox:
pip install 'platinum-sdk[adk]'
from google.adk.agents import Agent
from google.adk.apps import App
from platinum.adk import PlatinumPlugin
plugin = PlatinumPlugin(cpu=2, ram_mb=2048) # PT_TOKEN / PT_API_URL
root_agent = Agent(model="gemini-flash-latest", name="sandbox_agent",
instruction="Run code in the Platinum sandbox.", tools=plugin.get_tools())
app = App(name="sandbox_app", root_agent=root_agent, plugins=[plugin]) # closing the runner deletes the sandbox
The sandbox (adk-<random>, pt-base unless template=) is created on the
first tool call, or attached with sandbox_id= (started if it is stopped, and
left running on close). Without plugins=[plugin], await plugin.close()
deletes it. Commands run under bash in working_dir (/workspace, created on
first use); a timeout up to 80 s is one exec request, a longer one (the tools'
default is 300 s) or none a managed process. A timeout reports timed_out, exit
code 124 and the output so far. Tool failures go back to the model as
{"status": "error", ...}. PlatinumEnvironment implements ADK's
BaseEnvironment, so EnvironmentToolset(environment=PlatinumEnvironment())
runs ADK's own Execute, ReadFile, EditFile and WriteFile in a sandbox.
import platinum does not import google.adk.
Limits worth knowing
- One
files.writebody is at most 128 MiB less 4 KiB (134,213,632 bytes). A larger body is refused whole with413 payload_too_large, and itsmax_bytesfield holds the limit; nothing is written. Split big files into parts under the limit, or fetch them directly inside the sandbox (execwithwget). exec/run_codeare buffered, not streaming — output arrives after the command exits (default timeout 30 s viatimeout_ms).run_codesource is capped at 1 MiB.- Template names and minimums are per-deployment.
pt-base(Debian with Python 3.12, pip, bash and apt-get; no git, node, curl, wget or nc until youapt-get installthem) exists on default installs; hosted deployments may only offer other templates with higher cpu/ram minimums. Calltemplates.list()first; a below-minimum create fails with a clear 400. - Background processes are reaped when their
execcall returns. Usesbx.process.start(...)for anything that has to keep running — it is owned by the guest agent, not by the request, and its output and exit code stay readable. The old workaround (setsid sh -c '<server loop>' >/dev/null 2>&1 < /dev/null &) still works but loses both.
Testing
pip install -e '.[test]' && pytest runs unit tests with httpx.MockTransport and
local loopback HTTP/SSE fixtures; it needs no external service or credentials.
tests/test_process_transport.py checks sync/async LF, CRLF and CR framing against
byte-exact stdout/stderr and exit-code oracles, with bounded connections and
teardown. This proves SDK transport parity, not guest execution or live-fleet
behavior. The live e2e is opt-in:
PT_E2E=1 PT_API_URL=… PT_TOKEN=… pytest test_e2e.py.
tests/test_openai_agents.py runs only when openai-agents is installed
(pip install -e '.[test,openai-agents]') and is skipped otherwise;
tests/test_deepagents.py likewise needs the deepagents extra,
tests/test_pydantic_ai.py the pydantic-ai extra, and tests/test_adk.py
the adk extra.
Examples
Every operation has runnable code in the guides: Quickstart (create → exec → delete), Expose a port, Managed processes.
License
MIT
Metadata
Release files for platinum-sdk 0.8.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| platinum_sdk-0.8.0.tar.gz | 239.0 kB | With provenance | Details for platinum_sdk-0.8.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| platinum_sdk-0.8.0-py3-none-any.whl | Python 3 | none | any | Details for platinum_sdk-0.8.0-py3-none-any.whl |
Total release size: 399.1 kB
Release files / platinum_sdk-0.8.0.tar.gz
| Download URL | platinum_sdk-0.8.0.tar.gz |
|---|---|
| Size | 239.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b72e02a1ce2b4b1703b55a719fba498f6c2fa21dab2621c7a113bfee58f109e6
|
|
BLAKE2b-256 checksum How to use checksums |
d7d0ae72db49ddf3194d1da19a0729b0ae86b2961eb0d48f4962a2e75a3b0866
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 20, 2026.
Transparency logRelease files / platinum_sdk-0.8.0-py3-none-any.whl
| Download URL | platinum_sdk-0.8.0-py3-none-any.whl |
|---|---|
| Size | 160.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
a4861120c5f3f8e797aa2d99b23ef54b9f82abb1b86ea335cd38b96f02de9660
|
|
BLAKE2b-256 checksum How to use checksums |
a842806b1d882ebb849862286d87f04c99593fcfd76b7faaaed56d30c9975865
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 20, 2026.
Transparency logSecurity for platinum-sdk 0.8.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for platinum_sdk-0.8.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 20, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.