12345678910111213141516171819import { Sandbox } from '@opencomputer/sdk'; import { Image } from '@opencomputer/sdk/node'; // Define an image with packages, env vars, and files const image = Image.base() .aptInstall(['curl', 'jq']) .pipInstall(['requests', 'pandas']) .env({ PROJECT_ROOT: '/workspace' }) .workdir('/workspace'); // Create a sandbox — the image is built on first run, cached after const sandbox = await Sandbox.create({ image, timeout: 300, onBuildLog: (log) => console.log(`build: ${log}`), }); const result = await sandbox.exec.run('which curl'); console.log(result.exitCode); // 0
image to Sandbox.create(), the server:apt/pip/npm, compiling a large toolchain), raise the build-phase RAM with .builderMemory(mb) / .builder_memory(mb).memoryMB:12345678// 8 GB to build… const image = Image.base() .aptInstall(['build-essential', 'cmake']) .runCommands('make -j') .builderMemory(8192); // …but the sandbox runs at whatever you ask for const sandbox = await Sandbox.create({ image, memoryMB: 4096 });
builderMemory doesn't change the cache key — it's a build resource, not image content.12345678910111213141516171819import { Image, Snapshots } from '@opencomputer/sdk/node'; const snapshots = new Snapshots(); // Define the image const image = Image.base() .aptInstall(['python3-pip']) .pipInstall(['pandas', 'numpy', 'scikit-learn']) .workdir('/workspace'); // Create a named snapshot with build log streaming await snapshots.create({ name: 'data-science', image, onBuildLogs: (log) => console.log(`build: ${log}`), }); // Now create sandboxes from the snapshot — instant, no build step const sandbox = await Sandbox.create({ snapshot: 'data-science' });
memoryMB to give it more RAM — useful when one branch needs more headroom than the base.12// Fork the snapshot with 8 GB instead of its captured size const sandbox = await Sandbox.create({ snapshot: 'data-science', memoryMB: 8192 });
memoryMB is clamped to a valid range, and the response's memoryMB reports the effective value:memoryMB: 1024 still boots at ~4 GB.memoryMB field works when forking from a checkpoint.1234567891011121314const snapshots = new Snapshots(); // List all snapshots const list = await snapshots.list(); for (const s of list) { console.log(`${s.name} — ${s.status}`); } // Get a specific snapshot const snapshot = await snapshots.get('data-science'); console.log(snapshot.status); // "ready" // Delete a snapshot await snapshots.delete('data-science');
Image class provides a fluent, immutable API for defining sandbox environments. Each method returns a new Image instance — the original is never modified.| Method | Description |
Image.base() | Start from the default OpenSandbox environment |
.aptInstall(packages) / .apt_install(packages) | Install system packages via apt-get |
.pipInstall(packages) / .pip_install(packages) | Install Python packages via pip |
.runCommands(...cmds) / .run_commands(*cmds) | Run shell commands during build |
.env(vars) | Set environment variables (written to /etc/environment) |
.workdir(path) | Set default working directory |
.addFile(path, content) / .add_file(path, content) | Embed a file with inline content |
.addLocalFile(local, remote) / .add_local_file(local, remote) | Read a local file into the image |
.addLocalDir(local, remote) / .add_local_dir(local, remote) | Read a local directory into the image |
.builderMemory(mb) / .builder_memory(mb) | RAM for the build phase (default 4 GB; doesn't affect the resulting sandbox) |
.toJSON() / .to_dict() | Return the image manifest |
.cacheKey() / .cache_key() | Compute SHA-256 content hash |
| Field | Type | Description |
id | string | Unique snapshot identifier |
name | string | Snapshot name |
status | string | "building", "ready", or "failed" |
contentHash | string | SHA-256 hash of the image manifest |
checkpointId | string | Linked checkpoint ID |
manifest | object | The declarative image manifest |
createdAt | string | ISO 8601 creation timestamp |
lastUsedAt | string | ISO 8601 last usage timestamp |