SandboxSDK & APITypeScript & JavaScript

TypeScript and JavaScript

Use @tangle-network/sandbox from Node.js 22 or later.

Install

bash
npm install @tangle-network/sandbox
npm install --save-dev tsx

Get a Tangle API key and set TANGLE_API_KEY in your environment. Add credit at id.tangle.tools before creating a sandbox.

Run a command

Save this program as example.ts and run npx tsx example.ts. It creates a sandbox, waits for it to start, runs a command, and deletes it.

example.ts
import { Sandbox } from '@tangle-network/sandbox';

const apiKey = process.env.TANGLE_API_KEY;
if (!apiKey) throw new Error('Set TANGLE_API_KEY');

const tangle = new Sandbox({
  apiKey,
  baseUrl: 'https://sandbox.tangle.tools',
});
const box = await tangle.create({
  maxLifetimeSeconds: 900,
});
await box.waitFor('running');

const result = await box.exec('node --version');
console.log(result.stdout);

await box.delete();

The same code runs as JavaScript in an .mjs file with node example.mjs. Each example includes its imports and client setup, so you can copy it independently.

Choose the next task