Getting Started / TypeScript SDK
TYPESCRIPT SDK
@scaledminds/sdk
The official TypeScript SDK for ScaledMinds.com. Works in Node.js 20+, Deno, Bun, and any fetch-capable runtime.
TypeScript 5.xNode.js 20+Bun 1.xDeno 2.x
Installation
# npm
npm install @scaledminds/sdk
# pnpm
pnpm add @scaledminds/sdk
# Bun
bun add @scaledminds/sdkInitialize the client
Create a client instance once and reuse it. API keys are scoped to a workspace and read from environment variables by convention.
import { ScaledMinds } from "@scaledminds/sdk";
const client = new ScaledMinds({
apiKey: process.env.SCALEDMINDS_API_KEY, // required
baseUrl: "https://api.scaledminds.com", // default
timeout: 30_000, // ms, default 30s
});
Provision a sandbox
Each sandbox is a Firecracker microVM. Boot times are consistently under 200 ms. Billing starts at the millisecond of first boot.
const sandbox = await client.environments.create({
image: "python3.12", // or "node22", "golang1.23", ...
vcpus: 1,
memoryMb: 512,
timeoutSeconds: 300, // hard upper bound; terminates automatically
env: {
MY_VAR: "hello",
},
});
// sandbox.id → "env_01jxyz..."
// sandbox.state → "running"
Execute commands
const result = await client.environments.exec(sandbox.id, {
command: "python3 -c \"import sys; print(sys.version)\"",
timeoutSeconds: 10,
});
console.log(result.stdout); // 3.12.x ...
console.log(result.exitCode); // 0
TC39 Explicit Resource Management
The SDK supports the using keyword (TC39 Stage 3, available in TypeScript 5.2+ with lib: ["esnext"]). The sandbox is terminated automatically when the block exits — even on errors.
// tsconfig.json: { "lib": ["esnext"], "target": "esnext" }
await using sandbox = await client.environments.create({
image: "python3.12",
vcpus: 1,
memoryMb: 512,
timeoutSeconds: 60,
});
const result = await client.environments.exec(sandbox.id, {
command: "echo 'TC39 resource management works'",
});
// Sandbox.terminate() called automatically here
Upload files
import { readFile } from "node:fs/promises";
const contents = await readFile("./script.py");
await client.environments.uploadFile(sandbox.id, {
path: "/workspace/script.py",
content: contents,
});
Terminate
Billing stops at the second of termination. Always terminate sandboxes you no longer need.
await client.environments.terminate(sandbox.id);
Error handling
import { ScaledMinds, ScaledMindsError } from "@scaledminds/sdk";
try {
await client.environments.create({ image: "unknown-image" });
} catch (err) {
if (err instanceof ScaledMindsError) {
console.error(err.code); // e.g. "IMAGE_NOT_FOUND"
console.error(err.statusCode); // 404
}
}