Commands and files
Run commands in the sandbox and use its filesystem to pass inputs and collect results.
Execute a command
import { Sandbox } from "@tangle-network/sandbox";
const apiKey = process.env.TANGLE_API_KEY;
if (!apiKey) throw new Error("Set TANGLE_API_KEY");
const client = new Sandbox({
apiKey,
baseUrl: "https://sandbox.tangle.tools",
});
const box = await client.create({
maxLifetimeSeconds: 900,
});
await box.waitFor("running");
const result = await box.exec("node --version", {
cwd: "/workspace",
env: { CI: "true" },
timeoutMs: 60000,
});
console.log(result.exitCode, result.stdout);
await box.delete();The TypeScript SDK returns stdout, stderr, and exitCode.
Use cwd, env, and timeoutMs to set the working directory, environment, and command timeout.
The HTTP command request uses timeout in milliseconds.
Read and write files
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');
await box.write('/workspace/message.txt', 'Hello from Tangle');
const content = await box.read('/workspace/message.txt');
console.log(content);
await box.delete();Paths refer to the sandbox filesystem.
Use /workspace for project files.
The SDK also provides upload() and download() for local files and binary data.
Run a server
Use a background process for servers that must keep running after a command returns. Then create a preview link for the app’s port.
Restrict outbound requests
Set egressPolicy at creation to allow specific domains.
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,
egressPolicy: {
mode: 'strict', allowDomains: ['docs.tangle.tools'],
includeImplicitDomains: false,
},
});
await box.waitFor('running');
const result = await box.exec(
`node -e "fetch('https://docs.tangle.tools').then(r => console.log(r.status))"`,
);
console.log(result.stdout);
await box.delete();Provisioned model endpoints may also be allowed by the platform.
Use box.egress to inspect or update the sandbox’s outbound policy.