The
together-sandbox SDK and CLI must be enabled for your organization for you to use them. Contact us to request access.together-sandbox package ships as a Python SDK, a TypeScript SDK, and a CLI. This page covers the core workflow. The full reference lives in the together-sandbox repo.
Installation
~/.local/bin, with no Node.js or npm required.
Authentication
The SDKs and CLI read your Together API key from theTOGETHER_API_KEY environment variable:
api_key in Python or apiKey in TypeScript.
Create a snapshot
Every sandbox starts from a snapshot. Create one from a public Docker image, or from a Docker build context. Both are processed by Together’s remote image builder, which also optimizes the image for fast cold starts, so you don’t need Docker installed locally.namespace@tag, so later calls can reference my-python@v1 instead of a snapshot ID.
To build from a Dockerfile instead, pass a build context: CreateContextSnapshotParams(context="./my-app") in Python, { context: "./my-app" } in TypeScript, or --context ./my-app in the CLI. The builder uses the Dockerfile in the context directory unless you point at another file with the dockerfile parameter.
Run commands in a sandbox
Create a sandbox from a snapshot. The create call starts the sandbox and returns a connected client, so there is no separate start step.@ on an argument resolves it as a snapshot alias.
Each sandbox gets 1 vCPU and 2 GiB of memory by default. Set cpu (0.1 to 16 cores) and memory_bytes or memoryBytes (1 to 8 GB per CPU) at creation to size it differently. The CLI flags are --cpu and --memory-bytes.
In Python, using the SDK or a sandbox as an async context manager closes the HTTP connection on exit. It does not terminate the sandbox. Call
terminate() when you’re done with it.Sandbox lifecycle
- Sandboxes run until you terminate them: Nothing cleans them up automatically unless you set a
ttlat creation or pass--rmtosandboxes runin the CLI.together-sandbox sandboxes listshows what is still running. - Termination is permanent: A terminated sandbox cannot be restarted.
- Sandboxes are ephemeral by default: Terminating one discards its filesystem.
- Snapshot on termination to keep state: Pass
snapshot={"aliases": ["my-app@v2"]}toterminate()in Python,{ snapshot: { aliases: ["my-app@v2"] } }in TypeScript, or--snapshot-alias my-app@v2tosandboxes terminatein the CLI. The produced snapshot also gets the aliassandbox:<sandbox_id>automatically. Create a new sandbox from that snapshot to continue where the old one left off.
Full reference
The complete reference, covering file and directory operations, streaming exec output, port discovery, filesystem watching, resource listing and tagging, retries, and error handling, lives in thetogether-sandbox repo:
Legacy SDK
The earlier code sandbox offering built on@codesandbox/sdk remains documented at Code sandbox legacy SDK for existing users. Use the together-sandbox SDK on this page for new integrations.