TypeScript SDK for the Porter Sandbox API.
Pre-release. Pilot for Porter's multi-language SDK rollout.
npm install porter-sandboximport { Porter } from 'porter-sandbox';
const porter = new Porter();
const sb = await porter.sandboxes.create({
image: 'python:3.11-alpine',
command: ['python', '-c', "print('hi')"],
});
console.log(await sb.logs());
await sb.terminate();Volumes can be created up front and mounted into sandboxes at launch:
const volume = await porter.volumes.create({ name: 'my-data' });
const sb = await porter.sandboxes.create({
image: 'python:3.11-alpine',
volume_mounts: { '/mnt/my-data': volume.id },
});Set PORTER_SANDBOX_API_KEY in your environment, or pass apiKey when constructing the client.
By default, the SDK connects to Porter's in-cluster sandbox API at
http://sandbox-api.porter-sandbox-system.svc.cluster.local:8080. Override it
with PORTER_SANDBOX_BASE_URL or by passing baseUrl.
Sandbox methods are all promise-based — launch many in parallel with Promise.all:
const sandboxes = await Promise.all(
commands.map((command) => porter.sandboxes.create({ image: 'python:3.11', command })),
);src/sandbox.ts— richSandboxhandle (hand-written ergonomic API)src/porter.ts,src/sandboxes.ts,src/volumes.ts,src/healthz.ts,src/readyz.ts— generated publicPorterclient and resource namespacessrc/_client.ts,src/_models.ts,src/enums.ts,src/_errors.ts,src/resources/— generated from the sandbox-api OpenAPI spec. Do not edit by hand.src/_baseClient.ts— hand-writtenfetch-based HTTP transport (auth, retries, error mapping)src/_config.ts,src/_retries.ts— hand-written runtime (env-var resolution, retry/backoff)
npm install
npm test
npm run typecheck
npm run buildTo pull in a fresh generation from the sdk-gen workspace:
./scripts/sync-generated.sh /path/to/sdk-gen/out/typescript