Skip to main content

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.

Limits worth knowing

  • One files.write body is at most 128 MiB less 4 KiB (134,213,632 bytes). A larger body is refused whole with 413 payload_too_large, and its max_bytes field holds the limit; nothing is written. Split big files into parts under the limit, or fetch them directly inside the sandbox (exec with wget).
  • exec/run_code are buffered, not streaming — output arrives after the command exits (default timeout 30 s via timeout_ms). run_code source is capped at 1 MiB.
  • Template names and minimums are per-deployment. pt-base (busybox — no git/pip/node/httpd inside; nc/wget available) exists on default installs; hosted deployments may only offer other templates with higher cpu/ram minimums. Call templates.list() first; a below-minimum create fails with a clear 400.
  • Background processes are reaped when their exec call returns. Use sbx.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 &, see examples/02_expose_service.py) 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.

Examples

Runnable scripts in examples/:

pip install platinum-sdk
PT_API_URL=… PT_TOKEN=… python packages/sdk-py/examples/01_create_exec_delete.py

License

MIT

Metadata

Release files for platinum-sdk 0.7.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for platinum-sdk 0.7.1
File Size Uploaded Provenance Actions
platinum_sdk-0.7.1.tar.gz 132.2 kB With provenance Details for platinum_sdk-0.7.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for platinum-sdk 0.7.1
File Interpreter ABI Platform Actions
platinum_sdk-0.7.1-py3-none-any.whl Python 3 none any Details for platinum_sdk-0.7.1-py3-none-any.whl

Total release size: 225.1 kB

Release files / platinum_sdk-0.7.1.tar.gz

Download URL platinum_sdk-0.7.1.tar.gz
Size 132.2 kB
Tags Source
SHA-256 checksum
How to use checksums
34c801f4d7f1edc8c0787897527e17c80dd5a2486e873e90e59b581f90efc693
BLAKE2b-256 checksum
How to use checksums
0b457117c7b2e2f16602cdb23291b235536daf7157ff613214eab489fad903e4
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 16, 2026.

Transparency log

Release files / platinum_sdk-0.7.1-py3-none-any.whl

Download URL platinum_sdk-0.7.1-py3-none-any.whl
Size 93.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e39237c0c1bc5cb5011b2b957ad7311bd97a9521513cfda2b197ee047c39268e
BLAKE2b-256 checksum
How to use checksums
3044b7af0e8d039e63df142e31146a96c947db57c22f6469893f77f61722c7f7
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 16, 2026.

Transparency log

Security for platinum-sdk 0.7.1

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.

Select from 2 files

Attestation for platinum_sdk-0.7.1.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 16, 2026.

Transparency log

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

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page