Morph
A sandbox per Morph Cloud instance. Snapshot-first VMs with pause/resume, instant branching and cached setup chains, via the morphcloud SDK.
Maintenance-only
Morph's TypeScript SDK (morphcloud) hasn't been updated since October 2025.
Only the Python SDK is still maintained. This adapter is kept correct and
working on morphcloud@0.0.20, but it won't gain new Morph features. If you
are starting fresh on Morph, check the state of the TypeScript SDK first.
Installation
morphcloud is an optional peer dependency of sbox-sdk, loaded lazily on first use.
pnpm add sbox-sdk morphcloudAuthentication
A single API key.
| Option | Env var | Required | Description |
|---|---|---|---|
apiKey | MORPH_API_KEY | required | MorphCloud API key. |
baseUrl | — | optional | Override the MorphCloud API base URL. |
imageId | — | optional | Default image to snapshot from when `template` is not a snapshot id (default "morphvm-minimal"). |
vcpus | — | optional | Default vCPUs for a lazily-created snapshot. |
memory | — | optional | Default memory (MB) for a lazily-created snapshot. |
diskSize | — | optional | Default disk size for a lazily-created snapshot. |
Morph is snapshot-first: pass a snapshot id as `template` to boot it directly, or any other value as an image to snapshot first.
morph() reads MORPH_API_KEY when you don't pass apiKey. Check the key with client.verify(). It makes one authenticated list call and never creates anything.
Usage
import { createSandboxClient } from "sbox-sdk";
import { morph } from "sbox-sdk/morph";
const client = createSandboxClient({
provider: morph({ apiKey: process.env.MORPH_API_KEY! }),
});
const sandbox = await client.create({
template: "morphvm-minimal", // a Morph image id, or a snapshot_… id
resources: { vcpus: 2, memoryMB: 4096, diskMB: 16384 },
env: { NODE_ENV: "production" },
lifecycle: { maxAgeMs: 30 * 60_000, onIdle: "pause", autoResume: true },
});
for await (const ev of sandbox.commands.run("npm test")) {
if (ev.type === "stdout") process.stdout.write(ev.data); // real streaming
}
await sandbox.pause(); // memory preserved
await sandbox.resume(); // same id
const [a, b] = await sandbox.fork({ count: 2 }); // instance.branch()Morph is snapshot-first:
template: "snapshot_…",fromSnapshot, or a built template boots that snapshot directly.- Anything else is a Morph image id. The adapter keeps one base snapshot per
(image, vcpus, memory, disk), found through a digest and reused on later creates, so creating a sandbox doesn't add a new snapshot each time. resourcesonly apply when booting from an image. A snapshot keeps the resources it was taken with.
How the spec maps
| Spec | Morph |
|---|---|
metadata, name | instance metadata (name is stored as sbox-name) |
lifecycle.maxAgeMs | ttlSeconds |
lifecycle.onIdle | ttlAction: pause → pause, stop/destroy → stop (Morph deletes the instance on stop) |
lifecycle.autoResume | setWakeOn(ssh, http) |
env, inline secrets | added to every command (Morph has no per-instance env) |
ports | exposed as HTTP services at create |
idempotencyKey | stored as metadata. A retry returns the instance that already exists |
volumes, network (anything except allow-all), GPUs, vault secrets | rejected with Validation |
lifecycle.idleTimeoutMs and region have no Morph equivalent, so they're ignored.
Templates
client.templates.build() chains Snapshot.setup(cmd). Morph caches each step by chain hash, so an unchanged prefix of steps is reused. Three sources are accepted:
// 1. A Morph image id (or a snapshot id) as the base
await client.templates!.build({ source: { image: "morphvm-minimal" } });
// 2. A snapshot you already have
await client.templates!.build({ source: { snapshot: "snapshot_abc" } });
// 3. A restricted Dockerfile: FROM <morph-image-id|snapshot_id> + shell-form RUN only
const tpl = await client.templates!.build({
source: {
dockerfile: `FROM morphvm-minimal
RUN apt-get update && apt-get install -y nodejs
RUN npm i -g pnpm`,
},
});
const sandbox = await client.create({ template: tpl });Every other Dockerfile instruction (COPY, ENV, WORKDIR, CMD and so on) is rejected with Validation. The same goes for registry images, template env, workdir, user, startCmd and readyCmd. The result is a snapshot tagged with the template cache key, so templates.get(cacheKey) finds it again. Setup output goes to the SDK's own stdout and isn't forwarded to onEvent. You only get one log event per step.
Previews
Ports are Morph HTTP services named sbox-<port>.
const pub = await sandbox.ports!.expose(3000); // auth: { type: "public" }
const priv = await sandbox.ports!.expose(8080, { visibility: "private" });
// priv.auth = { type: "header", headers: { Authorization: "Bearer <MORPH_API_KEY>" } }Morph's private mode (auth_mode: "api_key") checks for your account API
key in an Authorization header. It has no query-token or signed-URL mode,
so private previews don't work from a browser (previewBrowserAuth: false),
and anyone you give the header to holds your full API key. Use public previews
for anything that faces a browser.
Capabilities
| Capability | Level | Notes |
|---|---|---|
list | native | filtered on the server by metadata |
streaming | native | SSE exec with stdout and stderr kept separate |
pause | native | instance.pause() / resume(). Memory preserved, id unchanged |
setTimeout | native | instance.setTTL() |
snapshot | native | instance.snapshot(). The name is stored in metadata. List and delete work |
fork | native | instance.branch(). The intermediate snapshot is deleted afterwards |
ssh | native | instance.sshKey() via ssh.cloud.morph.so |
exposePort | native | exposeHttpService |
privatePreview | native | header auth with the account API key (see above) |
templateBuild | native | Snapshot.setup() chains |
filesUpload | emulated | exec + base64, in 48 KB chunks so large files round-trip |
stop | unsupported | Morph's stop deletes the instance. Use pause() or destroy() |
background, pty, stdin, egressControl, volumes, metrics, codeInterpreter | unsupported |
Flags:
perCommandEnvCwd: false: the core addscwd/envto the command itself.preservesMemoryOnPause: trueandpreviewModel: "subdomain".- No in-place
snapshots.restore(). To restore, boot a new sandbox withclient.create({ fromSnapshot }).
Known limitations
connect()dropsspec.env. Env fromcreate()is held by the handle thatcreate()/fork()return. A sandbox you get back withclient.connect(id)doesn't have it.kill()ends the stream right away (exit code 137). It then kills the remote process tree with a second exec that finds processes by a per-command marker env var. A command that clears its own environment can survive this.timeoutMsis passed to Morph in whole seconds, rounded up. On timeout the adapter also kills the remote process.- File I/O is exec + base64, so a 5 MB write takes about 100 exec round-trips.
ssh.create()returns the instance's SSH key with the instance id as the user. The exact gateway username format hasn't been checked against a live account.
AWS Lambda MicroVMs
Firecracker-based serverless sandboxes with suspend/resume and idle policies. Control plane via @aws-sdk/client-lambda-microvms; a small runner baked into the image handles exec and files.
Cloudflare Sandbox
Cloudflare Sandbox SDK 0.12 through a Worker / Durable Object binding. Deprecated; a 1.0 adapter is planned.