PLATINUM DOCS

Migrate from Modal

Map Modal sandbox calls to Platinum SDK calls, port Modal Image builds to templates, and see what behaves differently.

Last updated

Platinum runs untrusted and AI-generated code in isolated sandboxes. This page maps Modal sandbox calls to Platinum SDK calls, for Modal's Python and JavaScript SDKs. It is for engineers who know Modal and are new to Platinum.

Install the SDK

Install the Platinum SDK in place of the modal package.

npm install @platinum-dev/sdk
pip install "platinum-sdk>=0.7"
npm install -g @platinum-dev/cli
# Nothing to install. Send requests to $PT_API_URL with your API key.

Authenticate

Modal reads MODAL_TOKEN_ID and MODAL_TOKEN_SECRET, or a token in ~/.modal.toml. Platinum reads one API key from PT_TOKEN. Create a key in the dashboard or with pt login. See API keys.

export PT_TOKEN=pt_live_…
export PT_API_URL=https://api.platinum.dev
VariableRead byMeaning
PT_TOKENTypeScript SDK, Python SDK, pt CLIThe API key.
PLATINUM_API_KEYpt CLI onlyThe API key. It wins over PT_TOKEN.
PLATINUM_API_URL, else PT_API_URLTypeScript SDK, Python SDK, pt CLIThe API base URL. The default is https://api.platinum.dev. The cURL examples below read PT_API_URL. platinum-sdk before 0.7.0 has no hosted default and reads only PT_API_URL: upgrade it.

With PT_TOKEN set, new Platinum() (TypeScript) and Platinum() (Python) need no arguments. new Platinum() replaces new ModalClient(). Platinum has no App, so drop modal.App.lookup(). A sandbox belongs to the organization of your API key.

Map Modal calls to Platinum

Modal creates a sandbox inside an App. Platinum creates it through a client: client.sandboxes.create(). In the table, sbx is a sandbox handle, r is an exec result, and p is a managed process.

Port the common flows

Create a sandbox, run a command, and delete it

Modal uses App.lookup(), Sandbox.create(), sb.exec(), and sb.terminate().

import { Platinum } from "@platinum-dev/sdk";

const client = new Platinum(); // reads PT_TOKEN and PT_API_URL
const sbx = await client.sandboxes.create({ template: "pt-base" }, { waitForRunning: true });
const r = await sbx.exec(["python3", "-c", "print(2+2)"]);
console.log(r.exit_code, r.stdout);
await sbx.delete();
from platinum import Platinum

client = Platinum()  # reads PT_TOKEN and PT_API_URL
sbx = client.sandboxes.create(template="pt-base", wait_for_running=True)
r = sbx.exec(["python3", "-c", "print(2+2)"])
print(r.exit_code, r.stdout)
sbx.delete()
SBX=$(pt sandbox create -t pt-base -q)
pt sandbox exec $SBX 'python3 -c "print(2+2)"'
pt sandbox rm $SBX
SBX=$(curl -sS -X POST "$PT_API_URL/v1/sandboxes?wait_for_state=running" \
  -H "Authorization: Bearer $PT_TOKEN" -H "Content-Type: application/json" \
  -d '{"template":"pt-base"}' | jq -r .id)
curl -sS -X POST "$PT_API_URL/v1/sandboxes/$SBX/exec" \
  -H "Authorization: Bearer $PT_TOKEN" -H "Content-Type: application/json" \
  -d '{"cmd":["python3","-c","print(2+2)"]}' | jq -r .result.stdout
curl -sS -X DELETE "$PT_API_URL/v1/sandboxes/$SBX" -H "Authorization: Bearer $PT_TOKEN"

Modal's exec takes each argument separately. Platinum takes one argv array, or one string that runs with sh -c. exec returns when the command exits, so you need no wait().

Write and read a file

Modal uses sb.filesystem.write_text(), read_text(), and list_files(). Platinum puts the path first.

await sbx.files.write("/workspace/test.txt", "Hello World!\n");
const text = new TextDecoder().decode(await sbx.files.read("/workspace/test.txt"));
const entries = await sbx.files.list("/workspace");
sbx.files.write("/workspace/test.txt", "Hello World!\n")
text = sbx.files.read("/workspace/test.txt").decode()
entries = sbx.files.list("/workspace")
pt sandbox fs write $SBX /workspace/test.txt 'Hello World!'
pt sandbox fs read $SBX /workspace/test.txt
pt sandbox fs ls $SBX /workspace
curl -sS -X PUT "$PT_API_URL/v1/sandboxes/$SBX/files?path=/workspace/test.txt" \
  -H "Authorization: Bearer $PT_TOKEN" --data-binary 'Hello World!'
curl -sS "$PT_API_URL/v1/sandboxes/$SBX/files?path=/workspace/test.txt" -H "Authorization: Bearer $PT_TOKEN"
curl -sS "$PT_API_URL/v1/sandboxes/$SBX/files/list?path=/workspace" -H "Authorization: Bearer $PT_TOKEN"

files.read returns bytes, so decode them for text. A write creates missing parent directories. To copy a local file in or out, use pt sandbox cp.

Run a long command and stream its output

Modal uses sb.exec(), reads p.stdout line by line, and calls p.wait(). On Platinum, start a managed process.

const p = await sbx.process.start({
  cmd: "for i in 1 2 3; do echo step $i; sleep 10; done",
  cwd: "/tmp",
  env: { LOG_LEVEL: "info" },
});
for await (const ev of p.stream()) {
  if (ev.type === "stdout") process.stdout.write(ev.text);
}
const done = await p.wait();
console.log(done.exit_code);
p = sbx.process.start("for i in 1 2 3; do echo step $i; sleep 10; done",
                      cwd="/tmp", env={"LOG_LEVEL": "info"})
for ev in p.stream():
    if ev.type == "stdout":
        print(ev.data, end="")
done = p.wait(timeout_ms=600_000)
print(done.exit_code)
# No dedicated CLI command for managed processes. Use the API passthrough.
H=$(pt api POST /v1/sandboxes/$SBX/processes \
  -d '{"cmd":"for i in 1 2 3; do echo step $i; sleep 10; done","cwd":"/tmp","env":{"LOG_LEVEL":"info"}}' | jq -r .handle)
pt api /v1/sandboxes/$SBX/processes/$H --query "wait_ms=55000" | jq .exit_code
pt api /v1/sandboxes/$SBX/processes/$H/logs | jq -r .stdout
H=$(curl -sS -X POST "$PT_API_URL/v1/sandboxes/$SBX/processes" \
  -H "Authorization: Bearer $PT_TOKEN" -H "Content-Type: application/json" \
  -d '{"cmd":"for i in 1 2 3; do echo step $i; sleep 10; done","cwd":"/tmp","env":{"LOG_LEVEL":"info"}}' \
  | jq -r .handle)
curl -sS "$PT_API_URL/v1/sandboxes/$SBX/processes/$H?wait_ms=55000" \
  -H "Authorization: Bearer $PT_TOKEN" | jq .exit_code
curl -sS "$PT_API_URL/v1/sandboxes/$SBX/processes/$H/logs" \
  -H "Authorization: Bearer $PT_TOKEN" | jq -r .stdout

exec times out after 30 s by default, and one call waits about 85 s at most. A managed process has no deadline unless you set timeoutMs (timeout_ms in Python). It keeps the last 256 KiB of each stream, so read its output while it runs. In Python, wait() gives up after 5 minutes by default and leaves the process running.

Expose a port

Modal uses encrypted_ports at create, then reads the URL from sb.tunnels().

await sbx.process.start({ cmd: "python3 -m http.server 8000" });
const { url } = await sbx.expose(8000);
console.log(url);
sbx.process.start("python3 -m http.server 8000")
print(sbx.expose(8000)["url"])
pt api POST /v1/sandboxes/$SBX/processes -d '{"cmd":"python3 -m http.server 8000"}'
pt sandbox expose $SBX 8000
curl -sS -X POST "$PT_API_URL/v1/sandboxes/$SBX/processes" \
  -H "Authorization: Bearer $PT_TOKEN" -H "Content-Type: application/json" \
  -d '{"cmd":"python3 -m http.server 8000"}'
curl -sS -X POST "$PT_API_URL/v1/sandboxes/$SBX/expose" \
  -H "Authorization: Bearer $PT_TOKEN" -H "Content-Type: application/json" \
  -d '{"port":8000}' | jq -r .url

The URL carries a token that expires after 1 day. A Modal tunnel URL has no token. For the same behavior, pass public: true to expose.

A request to the URL starts a stopped sandbox. See Use preview URLs.

Snapshot a sandbox and start a copy

Modal uses sb.snapshot_filesystem(), then passes the result to Sandbox.create(image=...).

const snap = await sbx.snapshot();
const c = await sbx.clone({ snapshotId: snap.id });
const copy = await client.sandboxes.connect(c.id);
await copy.waitRunning();
snap = sbx.snapshot()
c = sbx.clone(snapshot_id=snap["id"])
new_sbx = client.sandboxes.connect(c["id"])
new_sbx.wait_running()
pt sandbox snapshot $SBX
pt sandbox clone $SBX   # clones the latest snapshot
SNAP=$(curl -sS -X POST "$PT_API_URL/v1/sandboxes/$SBX/snapshot" \
  -H "Authorization: Bearer $PT_TOKEN" | jq -r .id)
curl -sS -X POST "$PT_API_URL/v1/sandboxes/$SBX/clone" \
  -H "Authorization: Bearer $PT_TOKEN" -H "Content-Type: application/json" \
  -d "{\"snapshot_id\":\"$SNAP\"}" | jq -r .id

A snapshot holds the disk only, so the copy cold-boots. Processes and memory do not carry over. /tmp starts empty on every cold boot, so its files do not carry over either. Keep files you need under /workspace. A snapshot stays until you delete it, and it bills while it exists. sbx.fork() takes a snapshot and clones it in one call.

Mount a volume

Modal uses Volume.from_name(..., create_if_missing=True) and volumes= at create.

const vol = await client.volumes.open("data"); // get or create
const sbx = await client.sandboxes.create(
  { template: "pt-base", volumes: { "/data": vol } },
  { waitForRunning: true },
);
vol = client.volumes.open("data")  # get or create
sbx = client.sandboxes.create(template="pt-base", volumes={"/data": vol},
                              wait_for_running=True)
pt api PUT /v1/volumes/data   # get or create
SBX=$(pt sandbox create -t pt-base -v data:/data -q)
curl -sS -X PUT "$PT_API_URL/v1/volumes/data" -H "Authorization: Bearer $PT_TOKEN"
curl -sS -X POST "$PT_API_URL/v1/sandboxes?wait_for_state=running" \
  -H "Authorization: Bearer $PT_TOKEN" -H "Content-Type: application/json" \
  -d '{"template":"pt-base","volumes":{"/data":{"volume":"data"}}}'

pt-base mounts volumes. A custom template built before volumes launched fails the mount with template_lacks_volume_support: rebuild it. Writes commit about every 5 seconds, on sync, and when the sandbox stops or is deleted. Other sandboxes see them after a pull(), which replaces reload_volumes().

Templates

A Modal Image is a chain of build steps in code. A Platinum template is an image plus default CPU, RAM, and disk. Pick one of the ports below.

Build from an image

Use this when your Modal code calls Image.from_registry(tag). Pin the tag: the build rejects floating tags such as latest.

import { Platinum, Template } from "@platinum-dev/sdk";

const client = new Platinum();
const tpl = await Template.fromImage("ubuntu:24.04")
  .build(client, { name: "my-agent", default_cpu: 2, default_ram_mb: 1024 });
from platinum import Platinum, Template

client = Platinum()
tpl = Template.from_image("ubuntu:24.04").build(
    client, "my-agent", default_cpu=2, default_ram_mb=1024)
pt template build my-agent --image ubuntu:24.04 --cpu 2 --ram 1024 --wait
curl -X POST "$PT_API_URL/v1/templates/from-image" \
  -H "Authorization: Bearer $PT_TOKEN" -H "Content-Type: application/json" \
  -d '{"name":"my-agent","image":"ubuntu:24.04","default_cpu":2,"default_ram_mb":1024}'

The image's own CMD or ENTRYPOINT runs at boot. See Build from an image.

Translate the Image chain into steps

Use this when your Modal code builds the image with methods. Write each method as a declarative builder step.

For example, take this Modal image:

image = (
    modal.Image.debian_slim(python_version="3.13")
    .apt_install("git", "curl")
    .uv_pip_install("pandas", "requests")
    .env({"LOG_LEVEL": "info"})
    .workdir("/app")
)

The same image as a step chain:

import { Platinum, Template } from "@platinum-dev/sdk";

const client = new Platinum();
const tpl = await Template.fromPythonImage("3.13-slim")
  .aptInstall(["git", "curl"])
  .pipInstall(["pandas", "requests"])
  .env("LOG_LEVEL", "info")
  .workdir("/app")
  .build(client, { name: "my-agent", default_cpu: 2, default_ram_mb: 1024 });
if (tpl.state === "failed") throw new Error(tpl.build_logs);
from platinum import Platinum, Template

client = Platinum()
tpl = (Template.from_python_image("3.13-slim")
       .apt_install(["git", "curl"])
       .pip_install(["pandas", "requests"])
       .env("LOG_LEVEL", "info")
       .workdir("/app")
       .build(client, "my-agent", default_cpu=2, default_ram_mb=1024))
if tpl["state"] == "failed":
    raise RuntimeError(tpl["build_logs"])
# No CLI command for a step chain. Put the cURL body in spec.json and use the API passthrough.
pt api POST /v1/templates/from-spec -d @spec.json
curl -X POST "$PT_API_URL/v1/templates/from-spec" \
  -H "Authorization: Bearer $PT_TOKEN" -H "Content-Type: application/json" \
  -d '{
    "name": "my-agent",
    "base_image": "python:3.13-slim",
    "steps": [
      { "op": "apt", "packages": ["git", "curl"] },
      { "op": "pip", "packages": ["pandas", "requests"] },
      { "op": "env", "key": "LOG_LEVEL", "value": "info" },
      { "op": "workdir", "path": "/app" }
    ],
    "default_cpu": 2,
    "default_ram_mb": 1024
  }'

A failed build does not throw. Check state before you use the template.

Build inline at create

Modal builds an Image when Sandbox.create() first uses it. To keep that pattern, pass the step chain as image at create.

import { Platinum, Template } from "@platinum-dev/sdk";

const client = new Platinum();
const image = Template.fromPythonImage("3.13-slim").pipInstall(["pandas"]);
const sbx = await client.sandboxes.create(
  { image },
  { waitForRunning: true, waitTimeoutMs: 600_000 },
);
from platinum import Platinum, Template

client = Platinum()
image = Template.from_python_image("3.13-slim").pip_install(["pandas"])
sbx = client.sandboxes.create(image=image, wait_for_running=True,
                              wait_timeout_ms=600_000)
# No CLI flag for an inline image spec. Put the cURL body in body.json and use the API passthrough.
pt api POST /v1/sandboxes --query "wait_for_state=running" -d @body.json
curl -X POST "$PT_API_URL/v1/sandboxes?wait_for_state=running&wait_timeout_ms=60000" \
  -H "Authorization: Bearer $PT_TOKEN" -H "Content-Type: application/json" \
  -d '{
    "image": {
      "base_image": "python:3.13-slim",
      "steps": [{ "op": "pip", "packages": ["pandas"] }]
    }
  }'

An identical spec reuses the cached build. An inline build must finish within 300 s. For a large image, build a named template first. See Build inline at sandbox create.

Build a Dockerfile from git

Modal's Image.from_dockerfile(path) reads a local Dockerfile. When the apps feature is enabled for your org, Platinum builds a Dockerfile from a git repo: pt template build my-agent --repo <url> --dockerfile Dockerfile. See Build from git.

When the template is ready, create sandboxes with template: "my-agent". This replaces image= in Sandbox.create().

Differences

Warning: a Platinum sandbox has no lifetime deadline, so it does not end when Modal's timeout would. A stopped sandbox still bills disk. Delete sandboxes you no longer need, or set auto_stop_minutes and auto_delete_days at create.

Next steps