# Custom sandbox templates: give your agent's sandboxes your toolchain, pinned by digest

> Build your own image, pin it by digest and register it as a Sandscale sandbox template with sandscale sandbox template init and build, then start sandboxes from it. When a template beats a snapshot or a setup script.

Build your own image, pin it by digest and register it as a Sandscale sandbox template with sandscale sandbox template init and build, then start sandboxes from it. When a template beats a snapshot or a setup script.

November 27, 2026 · 4 min read · The Sandscale team

**Short answer:** if every agent run starts by installing the same compilers and packages, put them in an image instead. Build and push the image yourself, pin its reference by digest (`name@sha256:...`), register it with `sandscale sandbox template build`, and start sandboxes with `--template NAME`. A digest names one exact image, so every run gets the same bits, and a changed upstream tag cannot change your agent’s environment underneath it.

All commands here are from the live [`sandscale sandbox` CLI reference](https://sandscale.dev/docs/reference/cli/sandbox), which is generated from the CLI itself.

## Template, snapshot or setup script?

|   | Setup script per run | Snapshot | Template |
| --- | --- | --- | --- |
| What it is | Commands the agent runs first | An archive of a sandbox’s `/workspace` | An image pinned by digest, with a default size |
| Good for | Small, fast installs | A prepared project directory (dependencies installed, data unpacked) | System packages, toolchains, anything outside `/workspace` |
| Needs network at run time | Usually | No | No |

A snapshot saves only `/workspace`, so system-level tools belong in a template. The two combine: start from a template, then from a snapshot of a prepared project. See [starting sandboxes from a prepared snapshot](https://sandscale.dev/blog/how-to-start-sandboxes-from-a-prepared-snapshot).

## 1. Build and push your image

Sandscale builds no images; that part is yours, with whatever you already use. A minimal example:

```dockerfile
FROM python:3.12-slim
RUN pip install --no-cache-dir pandas==2.2.3 pytest==8.3.3
```

Build it, push it to your registry, and note the digest your registry reports for the pushed image.

## 2. Write the template file

```sh
sandscale sandbox template init --name data-py --image registry.example.com/team/data-py@sha256:DIGEST
```

`init` writes the template file in the current folder and sends nothing. Use your own registry path, and put the digest your registry reported in place of `DIGEST`. Keeping the file in the repository next to the Dockerfile means a template change goes through review like any other change.

## 3. Register it

```sh
sandscale sandbox template build --version 1.0.0 --cpus 2 --mem 4096
```

`build` registers the template the file and the options describe. `--cpus`, `--mem` and `--disk` set its default size. The vCPU you can use per box depends on your plan (Free up to 2, Pro and Team up to 16), and each vCPU comes with 4 GiB of memory; memory above that counts as extra vCPU-hours.

`sandscale sandbox template list` shows the templates you may use, and `sandscale sandbox template delete NAME --yes` removes one.

## 4. Start sandboxes from it

From the CLI:

```sh
sandscale sandbox start --template data-py --ttl 1h --network none
sandscale sandbox run --sync . --template data-py -- pytest -q
```

From the [TypeScript SDK](https://sandscale.dev/docs/sdks/typescript), `template` takes a template ID of your organization:

```js
const box = await sandscale.sandboxes.create({ template: 'TEMPLATE_ID', timeoutSeconds: 1800 });
```

Use the ID that `sandscale sandbox template list` shows. With a template, nonzero `cpuCount` values must match it; the server checks.

## Updating a template

Rebuild and push the image, take the new digest, update the reference in the template file, and run `template build` again with a new `--version`. With the template file in git, its history shows which image each version pointed to. [Reproducible agent runs](https://sandscale.dev/blog/reproducible-agent-runs) covers what else to pin.

## Policy still applies

Which templates, sizes and run times members may use is set by your organization’s [policies](https://sandscale.dev/docs/concepts/approvals), and a request outside them is refused before anything starts. A custom template does not get around that. Every [Sandscale sandbox](https://sandscale.dev/sandboxes) started from it is still its own Firecracker microVM.

## FAQ

### How do I create a custom sandbox template in Sandscale?

Build and push your own image, run `sandscale sandbox template init` with the image reference pinned by digest, then `sandscale sandbox template build` to register it. Start sandboxes with `--template NAME`.

### Does Sandscale build the image for me?

No. The CLI reference says Sandscale builds no images. You build and push the image yourself and register its digest-pinned reference as a template.

### Why pin the image by digest instead of a tag?

A tag can point to a different image tomorrow. A digest names exactly one image, so every sandbox from the template starts with the same contents.

### Should I use a template or a snapshot?

Use a template for system packages and toolchains, and a snapshot for a prepared `/workspace`, such as installed project dependencies. A snapshot covers only `/workspace`.

## Related

- [Sizing sandboxes: vCPU and memory](https://sandscale.dev/blog/sizing-sandboxes-vcpu-memory)
- [Supply chain risk when agents install packages](https://sandscale.dev/blog/supply-chain-risk-when-agents-install-packages)
- [Monitoring a sandbox’s CPU, memory and runs](https://sandscale.dev/blog/monitoring-sandbox-cpu-memory-and-runs)

**On this page**

1. Template, snapshot or setup script?
2. 1. Build and push your image
3. 2. Write the template file
4. 3. Register it
5. 4. Start sandboxes from it
6. Updating a template
7. Policy still applies
8. FAQ
9. Related

**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

- [November 27, 2026 · **A LlamaIndex.TS data agent that runs its Python in a Sandscale sandbox** · Use LlamaIndex.TS's agent workflow with tools that write and run Python in a Firecracker sandbox, built per sandbox so a run can only reach its own box. Upload data files, answer with the numbers, clean up. Type-checked.](https://sandscale.dev/blog/llamaindex-ts-agent-with-sandscale)
- [November 27, 2026 · **A sandbox for Claude Code: running it headless in a cloud workspace** · Run Claude Code with claude -p inside a Sandscale workspace, a persistent Firecracker microVM, so its Bash tool works on a cloud disk instead of your laptop. Setup, permission flags and what stays where.](https://sandscale.dev/blog/claude-code-headless-in-a-cloud-workspace)

---
Source: https://sandscale.dev/blog/custom-sandbox-templates-pinned-by-digest
