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/sdkpip 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| Variable | Read by | Meaning |
|---|---|---|
PT_TOKEN | TypeScript SDK, Python SDK, pt CLI | The API key. |
PLATINUM_API_KEY | pt CLI only | The API key. It wins over PT_TOKEN. |
PLATINUM_API_URL, else PT_API_URL | TypeScript SDK, Python SDK, pt CLI | The 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.
| E2B | Platinum TypeScript | Platinum Python | Page |
|---|---|---|---|
Sandbox.create() | client.sandboxes.create({}, { waitForRunning: true }) | client.sandboxes.create(wait_for_running=True) | Create |
Sandbox.create("my-tpl") | client.sandboxes.create({ template: "my-tpl" }) | client.sandboxes.create(template="my-tpl") | Create |
Sandbox.connect(id) | client.sandboxes.connect(id) | client.sandboxes.connect(id) | Get |
getInfo() / get_info() | client.sandboxes.get(id) | client.sandboxes.get(id) | Get |
Sandbox.list() | client.sandboxes.list({ state: "running" }) | client.sandboxes.list(state="running") | List |
commands.run(cmd) | sbx.exec(cmd) | sbx.exec(cmd) | Run a command |
commands.run(cmd, { background: true }) | sbx.process.start({ cmd }) | sbx.process.start(cmd) | Managed processes |
command.wait() / command.kill() | p.wait() / p.kill() | p.wait() / p.kill() | Managed processes |
runCode(code) / run_code(code) | sbx.runCode(code, { lang: "python" }) | sbx.run_code(code, lang="python") | Run code |
files.read(path) | sbx.files.read(path) returns Uint8Array | sbx.files.read(path) returns bytes | Read and write |
files.write(path, data) | sbx.files.write(path, data) | sbx.files.write(path, data) | Read and write |
files.list(path) | sbx.files.list(path) | sbx.files.list(path) | List, stat, mkdir |
makeDir · remove · exists · getInfo | files.mkdir · files.delete · files.exists · files.stat | files.mkdir · files.delete · files.exists · files.stat | Filesystem |
watchDir(path, onEvent) | sbx.files.watch(path) (async iterator) | sbx.files.watch(path) (generator) | Watch for changes |
Upload with files.write, download with files.read | sbx.files.write / sbx.files.read | sbx.files.write / sbx.files.read | Read and write |
getHost(port) / get_host(port) | (await sbx.expose(port)).url | sbx.expose(port)["url"] | Expose a port |
timeoutMs / timeout at create | client.sandboxes.create({ auto_stop_minutes: 15 }) (stops after 15 idle minutes) | client.sandboxes.create(auto_stop_minutes=15) (stops after 15 idle minutes) | Retention |
setTimeout() / set_timeout() | No equivalent. See Differences. | No equivalent. See Differences. | Retention |
pause() | sbx.pause() | sbx.pause() | Stop and start |
Sandbox.connect(id) on a paused sandbox | sbx.start({ waitForRunning: true }) or sbx.resume() | sbx.start(wait_for_running=True) or sbx.resume() | Stop and start |
kill() | sbx.delete() (alias sbx.kill()) | sbx.delete() (alias sbx.kill()) | Delete |
Template().fromImage(ref) with Template.build() | Template.fromImage(ref).build(client, { name }) | Template.from_image(ref).build(client, name) | Templates |
e2b.Dockerfile | A template from an image, or a step chain | A template from an image, or a step chain | Templates |
envs at create | client.sandboxes.create({ env }) | client.sandboxes.create(env={...}) | Create |
commands.run(cmd, { envs }) | sbx.process.start({ cmd, env }) | sbx.process.start(cmd, env={...}) | Managed processes |
metadata at create | client.sandboxes.create({ metadata }) | client.sandboxes.create(metadata={...}) | Create |
allowInternetAccess: false | client.sandboxes.create({ allowInternetAccess: false }) | client.sandboxes.create(allow_internet_access=False) | Block internet access |
network: { allowOut, denyOut } | client.sandboxes.create({ network: { allowOut, denyOut } }) | client.sandboxes.create(network={"allow_out": ..., "deny_out": ...}) | Allow only some destinations |
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 $SBXSBX=$(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 /tmpcurl -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 .stdoutH=$(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 .stdoutThe 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 waitsbx.pause() # returns once the sandbox is stopped
sbx.start(wait_for_running=True) # resume() also works, without the waitpt sandbox pause $SBX
pt sandbox wait $SBX --state stopped
pt sandbox resume $SBX
pt sandbox wait $SBXcurl -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 --waitcurl -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.
e2b.Dockerfile or E2B template | Platinum step (TypeScript / Python) |
|---|---|
FROM <image> | Template.fromImage(ref) / Template.from_image(ref) |
RUN <cmd> | .runCmd(cmd) / .run_cmd(cmd) |
ENV KEY=value | .env(key, value) |
WORKDIR <path> | .workdir(path) |
USER <user> | .user(user) |
COPY <src> <dst> | .copy(src, dst), up to 256 KiB per file |
CMD, ENTRYPOINT, or setStartCmd() | .entrypoint(cmd) |
setReadyCmd() | .readyCmd(cmd) / .ready_cmd(cmd). It does not gate boot. |
cpuCount, memoryMB | default_cpu, default_ram_mb in build() |
ADD, ARG | No step. Fetch remote files with .runCmd() and write values inline. |
For example, take this e2b.Dockerfile:
FROM python:3.13-slim
RUN pip install pandas requests
ENV LOG_LEVEL=info
WORKDIR /appThe 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.jsoncurl -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.
| Area | E2B | Platinum |
|---|---|---|
| Lifetime | timeoutMs sets a deadline. At the deadline, the sandbox is killed or paused. setTimeout() resets it. | A sandbox stays until you delete it, or until its retention timers do. auto_stop_minutes stops an idle sandbox. The SDKs set it at create only. See Retention. |
| Reconnect | Sandbox.connect() resumes a paused sandbox. | connect() returns a handle only. Call start() or resume(). A request to a preview URL also starts a stopped sandbox. |
| Pause | pause() saves the filesystem and memory. | pause() is an alias of stop(). It keeps memory where it can. The sandbox then reports stopped. See What a stop saved. |
| Command output | onStdout and onStderr stream output. | exec returns all output when the command exits. It times out after 30 s by default, and one call waits about 85 s at most. To stream output, start a managed process. A managed process keeps the last 256 KiB of each stream and drops older bytes, so read its output while it runs. |
| Per-command options | commands.run() takes envs. | exec has no per-call cwd or env. Use a shell string such as cd /app && make, or a managed process. |
| Default user | The default user is user. | Sandboxes give you a root shell. |
| Code interpreter | runCode() keeps variables between calls. It returns rich results, such as charts. | runCode() keeps no state between calls. Output is text only: stdout, stderr, and exit_code. Write plots to files. Languages are python, node, bash, and sh, and the interpreter must be in the template. |
| File reads | files.read() returns text, bytes, a Blob, or a stream. | files.read() returns bytes. |
| Many files | files.write([...]) and write_files() write many files in one call. | Send one file per call. |
| Rename | files.rename() | No rename call. Run mv with exec. |
| Watch | watchDir() calls a callback. | files.watch() is best-effort and does not report deletions. It ends after maxSeconds. |
| Signed file URLs | uploadUrl() and downloadUrl() | No signed file URLs. Use files.write, files.read, or pt sandbox cp. Size caps are in Limits. |
| Public URL | getHost() returns a host. By default, anyone with the URL reaches the port. | expose() returns a URL with a token by default. The token expires after 1 day. Pass public: true for a URL without a token. |
| Metadata | Sandbox.list() filters by metadata. | metadata (up to 16 KiB) comes back on reads. list has no metadata filter. |
| Templates | fromDockerfile() parses a Dockerfile. The build snapshots the start command while it runs. | The SDK has no Dockerfile parser. entrypoint starts at each boot. Image tags must be pinned. |
Next steps
- Sandboxes: lifecycle states, retention timers, stop and start
- Managed processes: servers, builds, and other long-running work
- Filesystem: search, replace, and watch files
- Networking: preview URLs, raw TCP ports, and outbound rules
- Templates and the declarative builder
- TypeScript SDK, Python SDK, and CLI references