Together SandboxBeta

Firecracker VMs booted from snapshots on Together AI (the successor to CodeSandbox). Remote Dockerfile builds, streamed execs, PTY, and hibernate/resume, via together-sandbox.

Installation

together-sandbox is an optional peer dependency of sbox-sdk, loaded lazily on first use.

pnpm add sbox-sdk together-sandbox

Together Sandbox is allowlist-only: your Together account needs sandbox access.

Authentication

OptionEnv varRequiredNotes
apiKeyTOGETHER_API_KEYyesTogether AI API key
baseUrlTOGETHER_BASE_URLnoManagement API host, without /v1
defaultTemplate—noSnapshot alias or id used when create() gets no template
const ok = await client.verify(); // one `sandboxes.list({ limit: 1 })` call, never creates

Usage

Every Together sandbox boots from a snapshot. There is no default image, so pass a template: a snapshot alias or id, or a TemplateSpec that is built on first use.

import { createSandboxClient } from "sbox-sdk";
import { together } from "sbox-sdk/together";

const client = createSandboxClient({
  provider: together({ apiKey: process.env.TOGETHER_API_KEY! }),
});

const sandbox = await client.create({
  template: {
    source: {
      dockerfile: "FROM node:22-bookworm\nRUN npm i -g pnpm\n",
    },
  },
  resources: { vcpus: 2, memoryMB: 4096 },
  metadata: { team: "agents" },
  env: { NODE_ENV: "production" },
});

const res = await sandbox.commands.run("node --version");
console.log(res.stdout);

Templates

client.templates.build() uses sdk.snapshots.create(), which builds remotely on Together's image builder. No local Docker is needed.

  • Dockerfile: the build context (a directory or in-memory files) is written to a temp dir and uploaded. TemplateSpec.env, workdir and user are appended as ENV, WORKDIR and USER lines.
  • Image: must be publicly pullable. registryAuth is rejected.
  • Snapshot: an existing snapshot id gets an alias.

Each built snapshot gets the alias <name>@<cacheKey prefix> and the tags sbox-template=1 and sbox-template-key=<cacheKey>. Together's native cacheKey is set to sbox/<name>, so rebuilds of one template reuse the remote layer cache. templates.get() finds a template by cache key, alias or snapshot id. templates.delete() retires the snapshot.

const ref = await client.templates!.build(
  {
    name: "borat-desktop",
    source: {
      dockerfile: "FROM debian:bookworm\nCOPY . /app\n",
      context: "./desktop",
    },
  },
  { onEvent: (e) => e.type === "log" && console.log(e.step, e.line) }
);
const sb = await client.create({ template: ref });

Pause, resume and new ids

Together's lifecycle is create → running → terminate:

  • pause() terminates with a memory snapshot (terminate({ snapshot: { memory: true } })). Processes resume intact.
  • stop() terminates with a filesystem-only snapshot.
  • resume() boots a new sandbox with a new id from the snapshot aliased sandbox:<id>. It keeps the CPU, memory, tags, TTL and termination policy.

capabilities.flags.resumeChangesId is true, so re-read the id after resume():

await sandbox.pause();
await sandbox.resume();
const { id } = await sandbox.getInfo(); // the new id; persist this one

The handle you hold keeps working after resume(), and getInfo().id returns the new id. sandbox.id is captured when the handle is built, so it still shows the old id. client.connect(oldId, { resume: true }) resumes and returns a sandbox bound to the new id.

After a resume, the parent's snapshot is retired, so the old id reads as destroyed. getOrCreate therefore never resumes the same parent twice.

getInfo() derives the state of a terminated sandbox from its sandbox:<id> snapshot:

Together statusSandboxState
starting, recoveringcreating
runningrunning
terminatingsuspending
failed_to_start, unrecoverederror
terminated + memory snapshotpaused
terminated + disk snapshotstopped
terminated, no live snapshotdestroyed

destroy() terminates without a snapshot. On a paused or stopped sandbox, it retires the snapshot instead.

Spec mapping

Spec fieldTogether
template / fromSnapshotsnapshotId (UUID) or snapshotAlias
resources.vcpus / memoryMBcpu / memoryBytes (disk is not configurable)
lifecycle.maxAgeMsttl (seconds from creation)
lifecycle.onIdlepause → memory snapshot when the TTL fires; stop → disk snapshot; otherwise ephemeral
metadata, nametags (name → sbox-name). Keys: at most 59 of [A-Za-z0-9._-], alphanumeric ends
env, inline secretsmerged into every exec and PTY, and persisted in /var/tmp/.sbox/env.json so reconnected handles reload them
idempotencyKeyhashed into an sbox-idem tag; a retried create reuses the sandbox
ports, network, volumes, region, GPU, vault secretsrejected with a Validation error

lifecycle.idleTimeoutMs and autoResume have no equivalent: Together has no idle detection and a terminated sandbox never wakes.

Capabilities

CapabilityLevelNotes
listnativecursor pages, tag and status filters on the server
pause / stopnativeterminate with a memory or disk snapshot; resume returns a new id
streaming / backgroundnativeexecs.create + streamOutput; stdout and stderr stay separate
killProcess / stdinnativeexecs.delete / execs.sendStdin (text)
ptynativeexecs.create({ pty: true }); resize via sendStdin({ type: "resize" }); pty.connect(id) replays output
filesWatch / filesUploadnativefiles.watch; binary-safe writes
templateBuildnativedockerfile, image, snapshot
exposePort / privatePreviewunsupportedthe sandbox model has no preview URL yet ("coming soon")
snapshot / forkunsupportedsnapshots exist only on terminate, which ends the sandbox
egressControlunsupportednetwork policy is inbound-only; outbound rules are not supported yet
setTimeout, metrics, ssh, volumes, gpu, region, secretsVaultunsupported

Flags: perCommandEnvCwd: true, exitCodeNative: true, preservesMemoryOnPause: true, preservesDiskOnStop: true, resumeChangesId: true, previewModel: "none".

Known limitations

  • File reads go through base64 in the VM. files.read returns a string, base64 for binary content with no marker. The adapter reads with base64 -w0 <path> instead, as Together's migration guide advises. Writes use the native binary upload.
  • Execs run as UID 1000 unless you pass user ("root", "0:0").
  • Exec timeouts are enforced by the sbox core, which kills the exec. Together has no native exec timeout.
  • Persisted env includes inline secret values in /var/tmp/.sbox/env.json, so they end up in pause/stop snapshots.

Migrating from the codesandbox adapter

The codesandbox adapter is deprecated. CodeSandbox's SDK became Together Sandbox.

sbox-sdk/codesandboxsbox-sdk/together
codesandbox({ apiKey: CSB_API_KEY })together({ apiKey: TOGETHER_API_KEY }) (CodeSandbox keys don't work)
template: a CSB template/sandbox idtemplate: a snapshot alias/id, or a TemplateSpec built from a Dockerfile
pause() (hibernate), same idpause() + resume(), new id: re-read getInfo().id
setTimeout() (hibernation timeout)lifecycle.maxAgeMs at create (TTL from creation, not idle)
ports.expose() (*.csb.app)not available yet

Rebuild your CodeSandbox templates as Dockerfiles. Existing templates and sandboxes can't be imported.

On this page