# Custom sandbox templates Build a template when you want each new sandbox session to start with the same tools and files. Each session gets a fresh copy. Changes you make in one session leave the template and the other sessions alone. A template belongs to the sandbox or app where you build it. The workspace owner builds and retires versions. People and agents with sandbox access can use a ready version. ## Build a template 1. Open your sandbox and select **Templates → Build template**. For an app, open **Sandboxes → Templates → Build template**. 2. Name the template, choose an approved base and enter the setup command you would normally run in a fresh session. If it downloads packages, the sandbox’s network settings must allow the registry. [Choose internet access](sandbox-environments.md#choose-internet-access). 3. Set the time limit and select **Build template**. The limit includes time spent waiting for a worker. The **Templates** tab refreshes automatically. When the version says **Ready**, you can start a session. The template saves files and process memory. Stop temporary services before your command finishes and keep credentials out of the build. Anyone who can start a copy can read what you left in it. If the build fails, open **Jobs** for its output. In **Templates**, select **Show recent history** to find a failed version. ## Use a template As the owner, open **Templates** and select **Start session** beside the ready version you want. Open that session’s terminal to use the tools you installed. Each new session uses the sandbox’s current network settings. [Work in a sandbox](sandbox-workbench.md). To update the tools, build another version. You can reuse the name. Each build has its own ID, so an agent can keep using a known version until you give it the new one. ## Use the API Use the same base path for the build and the sessions that use it. | Where the template belongs | Base path | | -------------------------- | ----------------------------------- | | Standalone sandbox | `/api/sandbox-environments/{envId}` | | App | `/api/apps/{appId}` | **Build.** As the workspace owner, send `POST {base}/sandbox-templates`. For an app, use your signed-in owner browser session. This example installs a Python package on a base with Python, pip and venv. Allow PyPI in the sandbox’s network settings first. ```json { "version": 1, "idempotencyKey": "22222222-2222-4222-8222-222222222222", "name": "python-tools", "command": "python3 -m venv /tmp/tools && /tmp/tools/bin/pip install --no-cache-dir packaging==25.0", "lifetimeSeconds": 300 } ``` Generate a fresh UUID for each build. Reuse it with the same body if you need to retry. A new build returns HTTP 202 with the template’s `id` and its `buildJobId`. Poll `GET {base}/sandbox-templates/{id}` until the state is `ready` or `failed`. Use `buildJobId` to [read output or cancel the build](sandbox-api.md#read-output-and-cancel). To supply setup files, use `files.inputs` as in the [jobs guide](sandbox-api.md#supply-files). Builds accept inputs only. **Start a copy.** With sandbox access, list versions using `GET {base}/sandbox-templates`. Send `POST {base}/sandbox-sessions` with a fresh request UUID and the ready version’s ID in `templateId`. Replace both UUIDs below. ```json { "version": 1, "idempotencyKey": "33333333-3333-4333-8333-333333333333", "templateId": "44444444-4444-4444-8444-444444444444", "lifetimeSeconds": 120 } ``` For the Python template above, run `/tmp/tools/bin/python -m pip show packaging` in the new session to check the installed version. The CLI’s `sandbox start --template` selects a base environment by its identity. Use the API’s `templateId` for a custom build. Command jobs and app-backed agent jobs also accept `templateId`. Choose either a template or a saved session (`snapshotId`) for each request. A deployed app uses the `/api/workloads/apps/{appId}` base with its `SANDBOX_API_TOKEN` and the incoming `X-Innie-Connector-Context` header. [Sandbox jobs](sandbox-api.md) · [Agent jobs](sandbox-agent.md). ## Retire a template In **Templates**, select **Retire** beside the version. Over the API, send `POST {base}/sandbox-templates/{id}/delete` with `{"version":1}`. New sessions can no longer start from that version. Existing copies can finish their work. When they release it and cleanup completes, the version shows `deleted`. To retire an unfinished build, cancel it in **Jobs** and wait for cleanup first. ## Limits Templates and named snapshots share an allowance of **4 per sandbox or app** and **16 per workspace**. Builds and versions awaiting deletion count toward the limit. Templates stay on the worker until retired and can be lost if its disk fails. Keep the setup command and input files in your repository so you can rebuild. [Workspace recovery](workspace-architecture.md#what-can-i-recover-if-a-worker-fails). You can install tools on any approved base your worker offers. Dockerfiles, arbitrary container images and custom kernels are outside the template format.