PLATINUM DOCS

Migrate from E2B

Map E2B SDK calls to Platinum SDK calls, port E2B templates, and see what behaves differently.

Last updated

Platinum runs untrusted and AI-generated code in isolated sandboxes. This page maps E2B SDK calls to Platinum SDK calls, so you can port code that uses e2b or @e2b/code-interpreter. It is for engineers who know the E2B SDK and are new to Platinum.

Install the SDK

Install the Platinum SDK in place of the E2B packages.

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

E2B reads E2B_API_KEY. Platinum reads 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. To pass the key in code, use token where E2B uses apiKey or api_key.

Map E2B calls to Platinum

E2B creates a sandbox with a static call: Sandbox.create(). Platinum creates it through a client: client.sandboxes.create(). In the table, sbx is the handle that create or connect returns.

Port the common flows

Create a sandbox, run a command, and delete it

E2B uses Sandbox.create(), sandbox.commands.run(), and sandbox.kill().

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("echo hello");
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("echo hello")
print(r.exit_code, r.stdout)
sbx.delete()
SBX=$(pt sandbox create -t pt-base -q)
pt sandbox exec $SBX 'echo hello'
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":"echo hello"}' | jq -r .result.stdout
curl -sS -X DELETE "$PT_API_URL/v1/sandboxes/$SBX" -H "Authorization: Bearer $PT_TOKEN"

A string command runs with sh -c. An argv array runs without a shell. exec returns when the command exits.

Write and read a file

E2B uses sandbox.files.write(), sandbox.files.read(), and sandbox.files.list().

await sbx.files.write("/tmp/hello.txt", "hello");
const text = new TextDecoder().decode(await sbx.files.read("/tmp/hello.txt"));
const entries = await sbx.files.list("/tmp");
sbx.files.write("/tmp/hello.txt", "hello")
text = sbx.files.read("/tmp/hello.txt").decode()
entries = sbx.files.list("/tmp")
pt sandbox fs write $SBX /tmp/hello.txt 'hello'
pt sandbox fs read $SBX /tmp/hello.txt
pt sandbox fs ls $SBX /tmp
curl -sS -X PUT "$PT_API_URL/v1/sandboxes/$SBX/files?path=/tmp/hello.txt" \
  -H "Authorization: Bearer $PT_TOKEN" --data-binary 'hello'
curl -sS "$PT_API_URL/v1/sandboxes/$SBX/files?path=/tmp/hello.txt" -H "Authorization: Bearer $PT_TOKEN"
curl -sS "$PT_API_URL/v1/sandboxes/$SBX/files/list?path=/tmp" -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.

Start a long process and read its output

E2B uses sandbox.commands.run(cmd, { background: true, onStdout }).

const p = await sbx.process.start({ cmd: "echo hello; sleep 10; echo world" });
for await (const ev of p.stream()) {
  if (ev.type === "stdout") process.stdout.write(ev.text);
  if (ev.type === "exit") break;
}
p = sbx.process.start("echo hello; sleep 10; echo world")
for ev in p.stream():
    if ev.type == "stdout":
        print(ev.data, end="")
    if ev.type == "exit":
        break
# No dedicated CLI command for managed processes. Use the API passthrough.
H=$(pt api POST /v1/sandboxes/$SBX/processes -d '{"cmd":"echo hello; sleep 10; echo world"}' | jq -r .handle)
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":"echo hello; sleep 10; echo world"}' | jq -r .handle)
curl -sS "$PT_API_URL/v1/sandboxes/$SBX/processes/$H/logs" \
  -H "Authorization: Bearer $PT_TOKEN" | jq -r .stdout

The process keeps running after the start call returns. stream() ends with an exit event. p.kill() stops the process. A logs read returns the output written so far.

Pause and resume

E2B uses sandbox.pause(), then Sandbox.connect(id) to resume.

await sbx.pause();                          // returns once the sandbox is stopped
await sbx.start({ waitForRunning: true });  // resume() also works, without the wait
sbx.pause()                       # returns once the sandbox is stopped
sbx.start(wait_for_running=True)  # resume() also works, without the wait
pt sandbox pause $SBX
pt sandbox wait $SBX --state stopped
pt sandbox resume $SBX
pt sandbox wait $SBX
curl -sS -X POST "$PT_API_URL/v1/sandboxes/$SBX/pause?wait_for_state=stopped" \
  -H "Authorization: Bearer $PT_TOKEN"
curl -sS -X POST "$PT_API_URL/v1/sandboxes/$SBX/resume?wait_for_state=running" \
  -H "Authorization: Bearer $PT_TOKEN"

Pause keeps memory and processes where it can. When it cannot, files survive and processes do not. A start that reaches running reports restore: memory or disk_only. See What a start restored.

Templates

Older E2B templates use an e2b.Dockerfile, and newer ones use code. A Platinum template is an image plus default CPU, RAM, and disk. Pick one of the three ports below.

Build from an image

Use this when your e2b.Dockerfile already builds an image in a registry. 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("ghcr.io/acme/agent:1.4.0")
  .build(client, { name: "my-agent", default_cpu: 2, default_ram_mb: 1024 });
from platinum import Platinum, Template

client = Platinum()
tpl = Template.from_image("ghcr.io/acme/agent:1.4.0").build(
    client, "my-agent", default_cpu=2, default_ram_mb=1024)
pt template build my-agent --image ghcr.io/acme/agent:1.4.0 --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":"ghcr.io/acme/agent:1.4.0","default_cpu":2,"default_ram_mb":1024}'

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

Translate the Dockerfile into steps

Use this when you have no registry. Write each instruction as a declarative builder step.

For example, take this e2b.Dockerfile:

FROM python:3.13-slim
RUN 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.fromImage("python:3.13-slim")
  .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_image("python:3.13-slim")
       .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": "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 the Dockerfile from git

When the apps feature is enabled for your org, Platinum builds a Dockerfile from a git repo. Name the file with --dockerfile: pt template build my-agent --repo <url> --dockerfile e2b.Dockerfile. See Build from git.

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

Differences

Warning: a Platinum sandbox has no lifetime deadline, so it does not end when E2B'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