# When a job needs a leased machine instead of a sandbox, from the live docs

> Sandboxes and build hosts solve different problems. How to tell which one a step of an agent's work needs, what a lease adds (pools, approvals, SSH certificates, a hard expiry), and how to move only the heavy step without moving the agent.

Sandboxes and build hosts solve different problems. How to tell which one a step of an agent's work needs, what a lease adds (pools, approvals, SSH certificates, a hard expiry), and how to move only the heavy step without moving the agent.

November 26, 2026 · 6 min read · The Sandscale team

An agent’s work is not one shape. Most of it is small and frequent: read a file, run one test, try a fix, run it again. Some of it is large and rare: the full test suite before opening a PR, a release build, a compile of the whole monorepo. Running both kinds in the same place usually means one of them is badly served. Either the small steps sit on a machine sized for the big ones, or the big ones crawl on a box sized for the small ones.

Sandscale has two products for this: sandboxes and build hosts. This post explains the difference using only what the [docs](https://sandscale.dev/docs/concepts/build-hosts) say, gives a rule of thumb for choosing, and shows how to hand just the heavy step to a leased machine.

## Two models of compute

**A sandbox is per run.** It is a Firecracker microVM with its own kernel, started for one run of an agent’s code, with the network your plan and your organization’s policy allow, and it goes away when you stop it ([sandboxes](https://sandscale.dev/docs/concepts/sandboxes)). You create it from code, run commands in it through the API, and stop it. The agent’s loop drives its life.

**A build host is leased.** It is a clean, large Linux machine your agent leases from a pool for a set time. The agent syncs its tree, runs over SSH, and releases the host when the task is done; on release the machine is wiped, so the next lease starts clean ([build hosts](https://sandscale.dev/build-hosts)). A lease has a state, a size and an expiry, and it can be renewed up to a hard limit.

The difference is not only size. It is who controls the machine’s existence. A sandbox exists because your code created it. A build host exists because a pool, set up by an administrator, agreed to lease it, possibly after a person approved the request.

## What a lease adds

Leasing brings a few controls that per-run sandboxes do not need:

- **Pools set by administrators.** A pool defines the kind of machine, its sizes, how long a lease may last, who may use it and whether a lease needs approval. Pools are managed in the console, not by the agent, and you see only the pools you may lease from.
- **Quotas checked before anything starts.** The organization’s, yours and the pool’s.
- **Optional approval.** A pool can require approval, in which case the lease waits as pending until someone approves it in the approvals inbox.
- **Access tied to the lease.** You connect over SSH with a short-lived certificate issued for your own public key. The SSH certificate and every Vault secret issued for a lease are valid only while the lease lasts.
- **A hard end.** A renewal can never pass the lease’s `hard_expires_at`. When a lease ends, by release, expiry, idleness or the kill switch, its cloud host is deleted. A request on an ended lease answers `409 lease_expired`.
- **A record of runs.** A run on a lease is recorded before it starts, so the lease keeps a history of what ran, with exit codes and logs.

These matter most for the jobs that tend to need real credentials. A release build may need a signing key. On a lease, that key does not outlive the machine, and the machine does not outlive the lease.

## A rule of thumb

Ask four questions about the step:

1. **Does it need more cores or memory than your sandboxes use for agent work?** A full suite sharded across many vCPUs is the classic case.
2. **Does it run for a long stretch as one job,** rather than as many short tool calls?
3. **Does it need credentials you would rather tie to a time-boxed, approved machine,** such as a signing key or a deploy token?
4. **Do you want a person, or a pool policy, to decide before it starts?**

If the answer to all four is no, it belongs in a sandbox. If one or more is yes, a lease is worth considering. In practice most agents end up with both: the loop stays in a sandbox, and one or two heavy steps go to a lease.

|   | Sandbox | Build host |
| --- | --- | --- |
| Unit | One run of the agent’s code | A lease for a set time |
| Created by | Your code, through the API | A pool, on request, sometimes after approval |
| Access | The sandbox API | SSH with a lease-scoped certificate |
| Credentials | Vault values for the run | Vault secrets valid only for the lease |
| Ends when | You stop it, or its timeout passes | Release, expiry, idleness or the kill switch |
| State afterwards | Gone when stopped | Host deleted; copy out what you need first |
| Plans | Every plan | Pro and up |

## Handing the heavy step to a lease

The flow below follows the [build hosts API guide](https://sandscale.dev/docs/guides/build-hosts-api). Routes live under your organization, so `ORG_ID` is your organization ID.

```sh
BUILD=https://api.sandscale.dev/api/v1/orgs/$ORG_ID/build
AUTH="Authorization: Bearer $SANDSCALE_API_KEY"

# 1. The pools you may lease from
curl "$BUILD/pools" -H "$AUTH"

# 2. Take a lease (size must be one of the pool's sizes)
curl -X POST "$BUILD/pools/$POOL_ID/leases" -H "$AUTH" -H "Content-Type: application/json" \
  -d '{"size": "SIZE", "ttl_seconds": 7200, "purpose": "full test suite", "repo": "github.com/acme/app"}'

# 3. A short-lived SSH certificate for your own key
curl -X POST "$BUILD/leases/$LEASE_ID/ssh/certificate" -H "$AUTH" -H "Content-Type: application/json" \
  -d "{\"public_key\": \"$(cat ~/.ssh/id_ed25519.pub)\"}"

# 4. Record the run, then release when results are copied out
curl -X POST "$BUILD/leases/$LEASE_ID/runs" -H "$AUTH" -H "Content-Type: application/json" \
  -d '{"argv": ["make", "test-all"], "cwd": "/workspace/app"}'
curl -X POST "$BUILD/leases/$LEASE_ID/release" -H "$AUTH"
```

Replace `SIZE` with one of the sizes the pool lists. The lease answer carries its `id`, `state`, `size`, `expires_at`, `hard_expires_at` and, once ready, its `host`.

From an orchestrator written in TypeScript, the SDK exposes the same lease calls. A small helper that takes a lease and always releases it:

```ts
import { Sandscale } from '@sandscale/sdk';

const sandscale = new Sandscale({ apiKey: process.env.SANDSCALE_API_KEY });

export async function withLease<T>(poolName: string, work: (leaseId: string) => Promise<T>): Promise<T> {
  const pools = await sandscale.buildHosts.listPools();
  const pool = pools.data.find((p) => p.name === poolName);
  if (!pool) throw new Error(`no pool named ${poolName} that you may lease from`);

  const lease = await sandscale.buildHosts.start(pool.id, {
    ttlSeconds: 7200,
    purpose: 'full test suite',
  });
  try {
    if (lease.state === 'pending_approval') {
      throw new Error(`lease ${lease.id} is waiting for approval in the approvals inbox`);
    }
    return await work(lease.id);
  } finally {
    await sandscale.buildHosts.stop(lease.id);
  }
}
```

In a real agent you would wait for approval rather than throw, but the shape is the point: the lease is released in `finally`, so a crash in the work does not leave a machine and its credentials alive until expiry.

## Things to plan for

- **The disk is not storage.** The host is wiped on release. Copy test reports, build artifacts and anything else you need out before you release. The docs say build artifacts and caches are kept with the lease and the pool; do not rely on the host’s disk beyond that.
- **Leases have a maximum length.** Each pool sets how long a lease may last, and a renewal cannot pass the hard expiry. On Team a lease lasts up to 12 hours. Design long jobs to checkpoint.
- **Idleness can end a lease.** Interactive SSH counts as activity, so a lease does not end for being idle while someone is working on it. A forgotten lease is a different matter.
- **Approval adds a person to the loop.** That is the feature. If a pool requires approval, the agent should report that it is waiting instead of retrying.
- **Cost uses the same unit.** Lease time draws from your plan’s monthly vCPU-hours, like sandboxes and workspaces ([build hosts](https://sandscale.dev/build-hosts)). See [pricing](https://sandscale.dev/pricing) for plan limits.

## Where to start

Keep the agent’s loop where it is. Pick the one step that hurts most, usually the full test suite, and move only that to a lease: take the lease when the agent reaches that step, run over SSH, copy the results back into the sandbox or your CI, and release. Build hosts come with Pro and up. The [concepts page](https://sandscale.dev/docs/concepts/build-hosts) and the [API guide](https://sandscale.dev/docs/guides/build-hosts-api) have the details, and the [build hosts and lab hosts API reference](https://sandscale.dev/docs/reference/api/build-hosts) lists every request.

**On this page**

1. Two models of compute
2. What a lease adds
3. A rule of thumb
4. Handing the heavy step to a lease
5. Things to plan for
6. Where to start

**Run your agents in a box of their own**

Each sandbox is a Firecracker microVM. Free includes 100 awake vCPU-hours a month.

[Start free](https://cloud.sandscale.dev/auth/signup)

## Keep reading

- [December 1, 2026 · **A team workflow for coding agents: who starts them, who approves, who reviews, who stops them** · When a team runs Claude Code, Codex or Cursor agents every day, someone has to own each step. A simple division of roles, a naming convention, and the Sandscale commands and controls behind each step, with no code to write.](https://sandscale.dev/blog/team-workflow-for-coding-agents)
- [December 1, 2026 · **Claude Code hooks that send the agent's Bash commands to its own machine, not your laptop** · A project rule asks Claude Code to run installs and test suites somewhere else. A PreToolUse hook makes it happen: it catches the Bash calls you choose and rewrites them to run on a Sandscale sandbox, with the change shown to you before it runs. The hook, the settings, and what it does not cover.](https://sandscale.dev/blog/claude-code-hooks-route-bash-to-a-sandbox)

---
Source: https://sandscale.dev/blog/build-hosts-vs-sandboxes
