Start a cloud agent
A cloud agent is a coding agent (Claude Code, Codex, OpenCode, or nanocode) running in its own Linux sandbox. It has a real filesystem, a shell, package installs, and git. It keeps working when your laptop sleeps, and you can run ten of them at once. You send it prompts from the SDK, the CLI, or HTTP, and you delete it, or let it stop itself, when the work is done.
Choose how the agent pays for its model
| Credential | Use it when | Model usage is billed to |
|---|---|---|
| Claude subscription | You have Claude Pro or Max and want Claude Code in the cloud. | Your Claude plan |
| ChatGPT plan or OpenAI key | You use Codex with your ChatGPT login or an OpenAI key. | Your ChatGPT plan or OpenAI account |
| Coding plan | You pay for Z.ai GLM, Kimi, MiniMax, or another provider's plan. | That provider |
| Tangle Router (default) | You want no setup: pass no credential at all. | Your Tangle credit |
Tangle bills sandbox compute per second in every case. With your own subscription or key, model tokens never touch your Tangle credit. See Cost, limits & spin-down.
Claude Code on your subscription, in one call
Create a token with claude setup-token (it prints a long-lived OAuth token
for your Claude account), then:
import { Sandbox } from "@tangle-network/sandbox";
const client = new Sandbox({
apiKey: process.env.TANGLE_API_KEY!,
baseUrl: "https://sandbox.tangle.tools",
});
// Once per token. The value is encrypted at rest and never returned.
await client.secrets.create("CLAUDE_TOKEN", process.env.CLAUDE_CODE_OAUTH_TOKEN!);
const agent = await client.create({
name: "my-claude",
backend: {
type: "claude-code",
model: {
cliAuth: { account: "me", secretEnv: "CLAUDE_TOKEN", format: "token" },
},
},
secrets: ["CLAUDE_TOKEN"],
git: { url: "https://github.com/your-org/your-repo" },
idleTimeoutSeconds: 900,
});
await agent.waitFor("running");
const result = await agent.prompt("Find the failing test and fix it.", {
sessionId: "fix-tests",
});
console.log(result.success, result.response);Or from a terminal:
tangle secret create CLAUDE_TOKEN --value-stdin <<< "$CLAUDE_CODE_OAUTH_TOKEN"
tangle sandbox create --name my-claude --backend claude-code --cli-auth CLAUDE_TOKEN \
--git-url https://github.com/your-org/your-repo --idle-timeout 900
tangle agent prompt <sandbox-id> "Find the failing test and fix it." --session fix-tests --streamThe sandbox is ready in seconds. The agent runs as a durable session:
sessionId keeps the conversation, so a second prompt() with the same id
continues where the first stopped, from this process or another one.
nanocode, with no credential
nanocode runs as backend.type: "nanocode". Pass no
credential and its model calls go through Tangle Router on your Tangle credit:
const nc = await client.create({
name: "my-nanocode",
backend: { type: "nanocode", model: { provider: "zai", model: "glm-5.3" } },
});
await nc.waitFor("running");
await nc.prompt("Create hello.txt containing nanocode-ok.", { sessionId: "hello" });A second prompt() with the same sessionId resumes the same nanocode session.
Watch it work
streamPrompt() yields events while the agent thinks, edits files, and runs
commands:
for await (const event of agent.streamPrompt("Now add a regression test.", {
sessionId: "fix-tests",
})) {
if (event.type === "message.part.updated") {
const part = event.data.part as { type?: string };
if (part?.type === "text" && typeof event.data.delta === "string") {
process.stdout.write(event.data.delta);
}
}
if (event.type === "done" || event.type === "result" || event.type === "error") {
break;
}
}Pick it up later
The sandbox and its sessions outlive your process. Keep agent.id, fetch the
sandbox from anywhere, and keep going:
const again = await client.get(agentId);
await again?.session("fix-tests").prompt("Open a pull request with the fix.");From a terminal, tangle agent prompt <sandbox-id> "…" --session fix-tests --stream continues the same session, tangle ssh <sandbox-id> opens a shell
beside the agent, and the dashboard shows the session live.
Spin it down
await agent.delete(); // permanent: the sandbox and its files are goneidleTimeoutSeconds stops an agent nobody is talking to, and
maxLifetimeSeconds caps how long it may run. A stopped sandbox keeps its
files and resumes with agent.resume(). See
Cost, limits & spin-down for a live cost meter.
How your credential is handled
- The token is stored as an encrypted account secret. The create request
carries only its name (
secretEnv), never its value. - The sandbox receives the token at start, and only for the harness you chose. The platform does not mint a Tangle model key for that sandbox.
- Delete the secret (
client.secrets.delete("CLAUDE_TOKEN")) or revoke the token at its provider to cut access.
Next
- Claude Code subscription: tokens, rotation, adding a token to a running sandbox, and HTTP.
- Codex & ChatGPT plan
- Coding plans (GLM, Kimi, MiniMax)
- Agent profiles: give the agent a role, instructions, and tools.
- Network egress rules: limit what the agent can reach.
- Multiple agents and Fleets: run many at once.