Move an agent from e2b or Modal to Tangle Sandbox
A Tangle sandbox gives an agent one machine with a persistent kernel, a shell, files and git. The parts an agent product needs next are built in: fleets, session replay, MCP, integrations and tool packs for the major agent frameworks. Examples that start from client or box use a client and sandbox made as in the first one.
Typed results from a kernel that remembers
runCode returns images, dataframes, JSON and HTML as typed results, in Python, JavaScript, TypeScript or Bash. Variables persist across calls in a session, so each tool call builds on the last one. An idempotencyKey turns a retry into a read: the same key in the same session returns the first result without running again, for 15 minutes.
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({ agent: false });
try {
// The kernel keeps `rows` for the next call in the same session.
await box.runCode("python", "rows = [{'city': 'Lisbon', 'temp': 21}, {'city': 'Oslo', 'temp': 9}]", { sessionId: "s1" });
const warmest = await box.runCode("python", "display(max(rows, key=lambda r: r['temp']))", {
sessionId: "s1",
idempotencyKey: "warmest-1",
});
console.log(warmest.results); // [{ type: "json", value: { city: "Lisbon", temp: 21 } }]
} finally {
await box.delete();
}Ran against production on 2026-11-23 with @tangle-network/sandbox 1.0.568; a retry with the same key returned the same result.
Shell, files and git on one machine
exec, fs.* and git.* act on the workspace your code runs in. A sandbox can start with your repository already cloned.
import { Sandbox } from "@tangle-network/sandbox";
const client = new Sandbox({
apiKey: process.env.TANGLE_API_KEY!,
baseUrl: "https://sandbox.tangle.tools",
});
// The clone finishes before create() resolves.
const box = await client.create({
git: { url: "https://github.com/tangle-network/sandbox-demo", ref: "main", depth: 1 },
});
try {
const status = await box.git.status();
console.log(status.branch, status.head, status.isDirty);
console.log((await box.exec("ls")).stdout);
} finally {
await box.delete();
}Snapshot, break, revert
A snapshot is the whole workspace: revert to it after a bad change, or start new sandboxes from it. The template gallery has workspaces to start from.
import { Sandbox } from "@tangle-network/sandbox";
const client = new Sandbox({
apiKey: process.env.TANGLE_API_KEY!,
baseUrl: "https://sandbox.tangle.tools",
});
// A snapshot is the whole workspace. Revert to it and the damage is gone.
const box = await client.create({
git: { url: "https://github.com/tangle-network/sandbox-demo" },
});
let ownedSnapshotId: string | undefined;
try {
const clean = await box.snapshot({ tags: ["clean"] });
ownedSnapshotId = clean.snapshotId;
await box.exec("rm -rf packages test");
console.log("after", (await box.exec("ls")).stdout.trim().split("\n"));
await box.revertToSnapshot(clean.snapshotId);
console.log("reverted", (await box.exec("ls")).stdout.trim().split("\n"));
} finally {
try {
if (ownedSnapshotId) await box.deleteSnapshot(ownedSnapshotId);
} finally {
await box.delete();
}
}From Snapshots.
Fleets under one budget
A fleet runs many agents at once, shares sandboxes between them, and stops at a budget you set in dollars.
const fleet = await client.fleets.create({
agents: [
{ agentId: "tests", task: "List the three slowest tests and why." },
{ agentId: "todos", task: "Find every TODO and group them by file." },
{ agentId: "deps", task: "Say what each dependency is used for." },
],
placement: { agentsPerSandbox: 3 },
defaults: {
git: { url: "https://github.com/tangle-network/sandbox-demo" },
backend: { type: "claude-code" },
maxLifetimeSeconds: 900,
},
budgetUsd: 1,
});
try {
const results = await fleet.runAll();
for (const r of results) console.log(r.agentId, r.status, r.result?.response);
console.log(await fleet.spend());
} finally {
await fleet.delete();
}From Fleets.
Turns that outlive your process
dispatchPrompt starts a turn and returns at once; the agent keeps working, and any process collects the result later. A turnId makes each turn of your agent loop run exactly once.
const run = await box.dispatchPrompt("Upgrade each dependency and run the tests.", {
sessionId: "upgrade-deps",
});
console.log(run.executionId, run.status, run.dispatched);
// Later, in any process.
const box2 = await client.get(sandboxId);
const result = await box2!.session("upgrade-deps").result({ executionId: run.executionId });
console.log(result.status, result.response);From Sessions.
Streams that survive a reload
The platform keeps each session's events. Pass the last event id you delivered and the stream replays everything after it, then continues live.
let lastEventId: string | undefined;
for await (const event of box.session(sessionId).events({ since: lastEventId })) {
lastEventId = event.id ?? lastEventId;
console.log(event.type);
}From Streaming.
MCP both ways
A hosted endpoint you paste into Claude, and a local stdio server for Claude Desktop, Cursor and Zed.
{
"mcpServers": {
"tangle-sandbox": {
"command": "tangle",
"args": ["mcp", "serve", "mcp-box"],
"env": { "TANGLE_API_KEY": "sk-tan-..." }
}
}
}From MCP.
Confidential sandboxes with attestation
A confidential sandbox runs inside a trusted execution environment and returns hardware attestation that binds the sandbox to it.
import { createConfidentialSandbox } from "@tangle-network/sandbox";
const { sandbox, attestation, attestationNonce } = await createConfidentialSandbox(client, {
driver: { type: "tangle" },
confidential: { tee: "tdx" },
attestationNonce: "auto",
requireAttestation: true,
});
try {
console.log(attestation?.tee_type, attestationNonce);
const fresh = await sandbox.getTeeAttestation({ attestationNonce: crypto.randomUUID().replaceAll("-", "") });
const key = await sandbox.getTeePublicKey();
console.log(fresh.attestation.timestamp, key.algorithm);
} finally {
await sandbox.delete();
}From Security.
Tool packs for agent frameworks
The sandbox becomes tools for your framework's loop: Anthropic, OpenAI, Vercel AI and Mastra.
import Anthropic from "@anthropic-ai/sdk";
import { Sandbox } from "@tangle-network/sandbox";
import { anthropicTools } from "@tangle-network/sandbox/agent";
const claude = new Anthropic();
const client = new Sandbox({
apiKey: process.env.TANGLE_API_KEY!,
baseUrl: "https://sandbox.tangle.tools",
});
const box = await client.create();
try {
const { tools, handleAssistantMessage } = anthropicTools(box, { sessionId: "chat-1" });
const messages: Anthropic.MessageParam[] = [
{ role: "user", content: "Plot sin(x) for x in [0, 2π] and describe the plot." },
];
for (let step = 0; step < 6; step++) {
const reply = await claude.messages.create({
model: "claude-opus-5-5",
max_tokens: 4096,
tools,
messages,
});
messages.push({ role: "assistant", content: reply.content });
if (reply.stop_reason !== "tool_use") break;
messages.push({ role: "user", content: await handleAssistantMessage(reply.content) });
}
} finally {
await box.delete();
}From Anthropic.
OAuth and API integrations
Your agent acts in GitHub, Slack, Stripe and the rest of the integration catalog: Integrations.
Migrating from e2b
The model is the same: create a sandbox, run code in a kernel, read typed results.
| e2b | Tangle |
|---|---|
Sandbox.create(...) | client.create() |
sandbox.runCode(code) | box.runCode("python", code, { sessionId }) |
result.results[0].png | result.results.find(r => r.type === "image").data |
sandbox.commands.run("...") | box.exec("...") |
sandbox.filesystem.write/read | box.write(path, content) / box.read(path) |
Tool packs and MCP bridges build on this surface, and the sandbox works without them.
Migrating from Modal
Move the work where an agent needs an interactive machine: files, git, a browser and kernel state that persists across many tool calls. For long parallel campaigns, a fleet gives you a coordinator and a workspace that every worker shares.