SandboxQuickstart

Quickstart: run your first sandbox

Create an API key, start a sandbox, run a command in it, give a coding agent a task, and delete the sandbox. Every step has a TypeScript, Python and CLI tab.

Get an API key

Create a key at id.tangle.tools/app/keys. Keys start with sk-tan-.

export TANGLE_API_KEY="sk-tan-..."

The key can create, run and delete every sandbox on your account. Keep it on a server, in a CI secret or in the CLI’s keychain. Browser code gets a short-lived token instead; see API keys and tokens.

Install

npm install @tangle-network/sandbox tsx

Save each program with the .mts extension and run it with npx tsx <file>.mts. Top-level await needs a module, and a .ts file in a new npm project compiles as CommonJS.

Create a sandbox and run a command

run-code.mts
import { Sandbox } from "@tangle-network/sandbox";
 
const client = new Sandbox({
  apiKey: process.env.TANGLE_API_KEY!,
  baseUrl: "https://sandbox.tangle.tools",
});
 
const box = await client.create();
try {
  const result = await box.exec("python3 -c 'print(sum(range(1_000_000)))'");
  console.log(result.exitCode, result.stdout);
} finally {
  await box.delete();
}
npx tsx run-code.mts
0 499999500000

client.create() returns once the sandbox is running. exec does not throw on a non-zero exit, so read exitCode.

Neither SDK reads environment variables, so pass baseUrl (base_url in Python) every time.

Give a coding agent a task

A new sandbox has a coding agent installed. Unless you give it your own credential, it calls models through the Tangle Router, which bills model use to your account. GET /v1/router-models lists the models your key can run; Router models describes them.

prompt.mts
import { Sandbox } from "@tangle-network/sandbox";
 
const client = new Sandbox({
  apiKey: process.env.TANGLE_API_KEY!,
  baseUrl: "https://sandbox.tangle.tools",
});
 
const box = await client.create();
try {
  const run = await box.prompt(
    "Write fizzbuzz.py for 1 to 15, run it, and reply with its output.",
  );
  if (!run.success) throw new Error(run.error ?? "Agent turn failed");
  console.log(run.response);
 
  const file = await box.exec("cat fizzbuzz.py");
  console.log(file.stdout);
} finally {
  await box.delete();
}
⚠️

prompt does not throw when the agent fails. Check success, then read response or error. A finished turn is not a finished task: check the work with a command, as the example does with cat.

Delete what you create

maxLifetimeSeconds and idleTimeoutSeconds stop a sandbox and keep its disk. They do not delete it. Delete in a finally block, as every example here does, or set deleteAfterStoppedSeconds. See Create, stop and delete.

What you did

  • Created an API key and a client pointed at https://sandbox.tangle.tools.
  • Started an isolated Linux sandbox and ran a command in it.
  • Gave the sandbox’s coding agent a task and checked its result.
  • Deleted the sandbox so it stopped billing.

Set up a coding agent to use Tangle Sandbox

If you work with a coding agent such as Claude Code or Codex, give it the setup skill at sandbox.tangle.tools/agent-setup.md. The CLI ships the same instructions; tangle skill path prints where its SKILL.md is installed.

Next steps