GPU leases

Attach a GPU worker for the part of a job that needs an accelerator. Set a maximum cost estimate and lifetime, run the job, then detach the lease.

Check resource sizes

Read the deployment’s CPU, memory, and disk presets and your account’s resource ceiling. Fleet driver capabilities report whether a driver supports accelerator requests.

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 shapes = await client.shapes();
console.table(shapes.presets);
console.log("Default:", shapes.default);
console.log("Account ceiling:", shapes.ceiling);
const { drivers } = await client.fleets.capabilities();
console.table(drivers.map(({ driverType, accelerators }) => ({ driverType, accelerators })));

These describe supported configurations, not GPU stock. GPU allocation depends on configured providers, available capacity, and the requested limits.

Attach a GPU and run a command

Set TANGLE_SANDBOX_ID to a running sandbox you own. The example requests an H100, runs nvidia-smi, and releases the GPU lease. It keeps the base sandbox for later work.

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 sandboxId = process.env.TANGLE_SANDBOX_ID;
if (!sandboxId) throw new Error("Set TANGLE_SANDBOX_ID");
const box = await client.get(sandboxId);
if (!box) throw new Error("Sandbox not found");
await box.waitFor("running");

const lease = await box.gpu.attach({
  accelerator: { kind: "nvidia-h100", count: 1 },
  maxSpendUsd: 5,
  maxLifetimeSeconds: 600,
  idleTimeoutSeconds: 120,
});
console.log("Lease:", lease.id, lease.provider, lease.status);
const { result } = await box.gpu.exec(lease.id, {
  command: "nvidia-smi",
  timeoutMs: 30000,
});
console.log(result.exitCode, result.stdout);
const stopped = await box.gpu.detach(lease.id);
console.log("Charge (USD):", stopped.billing?.customerCostUsd);

gpu.exec() runs on the GPU worker; box.exec() runs in the base sandbox. The worker has its own filesystem. Pass inputs through storage or explicit transfers instead of assuming it shares /workspace.

OptionMeaning
accelerator.kindGPU class, such as nvidia-h100.
accelerator.countNumber of devices.
accelerator.memoryMBMinimum device memory when the class is flexible.
maxSpendUsdMaximum accepted cost estimate for the requested lifetime, in US dollars.
maxLifetimeSecondsMaximum lease lifetime.
idleTimeoutSecondsRelease the lease after this idle interval.
providerRequest a specific configured provider; omit it for provider selection.
imageContainer image for the GPU worker.

The attach response includes the chosen provider and any available rate and selection details.

Inspect leases and charges

List the sandbox’s leases to inspect their states, rates, final charges, and failures.

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 sandboxId = process.env.TANGLE_SANDBOX_ID;
if (!sandboxId) throw new Error("Set TANGLE_SANDBOX_ID");
const box = await client.get(sandboxId);
if (!box) throw new Error("Sandbox not found");
await box.waitFor("running");

for (const lease of await box.gpu.list()) {
  console.log(lease.id, lease.provider, lease.status);
  console.log("Customer rate per hour (USD):", lease.customerPricePerHourUsd);
  console.log("Final charge (USD):", lease.billing?.customerCostUsd);
  if (lease.failure) console.log("Failure:", lease.failure);
}
StateMeaning
provisioningThe GPU worker is being created.
readyThe worker can accept commands.
detachingThe provider is releasing the worker.
destroyedThe lease has ended.
failedProvisioning or a lease operation failed; inspect failure.

customerPricePerHourUsd is a rate. billing.customerCostUsd is the finalized lease charge when reported. A missing billing field does not mean the job was free.

Release resources

Call box.gpu.detach(leaseId) when GPU work finishes. The returned lease includes its final state and billing details when available. Delete the base sandbox separately when its remaining work is done. See sandbox lifecycle for stopping and deleting it.