Sandbox VMs
A Sandbox VM is a single VM that your sandboxes run on, in one region. Nirvana
builds and runs it for you. It is a Nirvana API resource at
/v1/sandbox_vms. Like a Sandbox Cluster,
it belongs to one of your projects. Unlike a Sandbox Cluster, you can pause
it and resume it later. A paused Sandbox VM is billed only for its disk.
You create, list, get, delete and connect to sandboxes on a Sandbox VM through
the same OpenSandbox
Sandbox Lifecycle API as on a Sandbox Cluster. Only the routing extension
differs: nirvana.sandbox_vm_id instead of nirvana.sandbox_cluster_id.
For every Sandbox VM endpoint, field and error, see the Sandbox VMs API reference.
Sandbox VM or Sandbox Cluster
Section titled “Sandbox VM or Sandbox Cluster”| Sandbox VM | Sandbox Cluster | |
|---|---|---|
| Compute | One VM. One size: n1-highcpu-2 (2 vCPU, 4 GiB). |
1 to 100 nodes of an instance type you choose. |
| Pause and resume | Yes. You pause and resume the whole Sandbox VM, not individual sandboxes. | No. |
| Billing while idle | A paused or powered-off Sandbox VM is billed only for its disk. | Billed until you delete it. |
| Network | Placed in a VPC in its project. | Reached through the cluster’s gateway hostname. |
| Reaching a sandbox port | A signed URL on api.nirvanalabs.io. You don’t need to send any headers. |
The gateway hostname plus routing headers the API returns. |
| Persistence | Pause and resume. Files and installed packages stay on the VM’s disk. | PVCs on the cluster. |
| Routing extension | nirvana.sandbox_vm_id |
nirvana.sandbox_cluster_id |
Choose a Sandbox VM when your agents work in bursts and you want to stop paying for compute between bursts, keeping their files and installed packages. A typical case is one environment per agent or per user, paused when idle.
Choose a Sandbox Cluster when you need more capacity than one small VM, a choice of instance type, many sandboxes running at once, or PVCs.
Availability
Section titled “Availability”- Sandbox VMs must be enabled for your organization. Until they are,
creating one fails with
403and theSANDBOX_VMS_NOT_ENABLEDerror type. The organization’sservices.sandbox_vmsfield shows whether they are enabled. - Sandbox VMs are available in
us-sva-2andus-wdc-1. In other regions, the create request fails with400and theREGION_PRODUCT_UNAVAILABLEerror type. - There is one size.
instance_typeis optional and defaults ton1-highcpu-2(2 vCPU, 4 GiB). Each Sandbox VM has a 30 GB data disk. - Quotas apply. Your organization can have a limited number of Sandbox VMs. A running Sandbox VM’s vCPU and memory count against the organization’s sandbox quota, which Sandbox Clusters use too.
Permissions
Section titled “Permissions”API keys have a sandbox_vm permission, separate from sandbox_cluster and
sandbox. See Authentication.
| Permission | Level | Needed to |
|---|---|---|
sandbox_vm |
read |
Get and list Sandbox VMs, get a cost quote, and poll the operations of Sandbox VMs. |
sandbox_vm |
edit |
Create, update, pause, resume, restart and delete Sandbox VMs. |
vpc |
read |
Create a Sandbox VM. With vpc_id, the key needs read on that VPC. Without vpc_id, it needs read on VPCs in the project. |
vpc |
edit |
Create a Sandbox VM in a project and region that have no ready VPC. A new VPC is created for it. See VPC placement. |
sandbox |
read |
List and get the sandboxes on the Sandbox VM. |
sandbox |
edit |
Create and delete sandboxes on it, get their endpoints, renew their expiration and update their metadata. |
Each permission applies to the Sandbox VM’s project, which must be in the key’s project scope. Organization members can read Sandbox VMs but can’t change them. Owners and admins can.
Quickstart
Section titled “Quickstart”In this quickstart you create a Sandbox VM, wait for it to be ready, run a sandbox on it with the OpenSandbox Python SDK, and then delete both.
You need:
- An organization with Sandbox VMs enabled, and a project ID.
- An API key with
sandbox_vmedit,vpcreadandsandboxediton that project. If the project has no ready VPC in the region, the key also needsvpcedit. curl,jq, and Python 3.10 or later.
export NIRVANA_API_KEY="REPLACE_WITH_YOUR_API_KEY"export PROJECT_ID="123e4567-e89b-12d3-a456-426614174000"export REGION="us-sva-2" # or us-wdc-11. Create a Sandbox VM
Section titled “1. Create a Sandbox VM”curl -sS -X POST https://api.nirvanalabs.io/v1/sandbox_vms \ -H "Authorization: Bearer $NIRVANA_API_KEY" \ -H "Content-Type: application/json" \ -d "{ \"project_id\": \"$PROJECT_ID\", \"name\": \"my-sandboxes\", \"region\": \"$REGION\" }" | tee create.json| Field | Required | Description |
|---|---|---|
project_id |
Yes | Project the Sandbox VM belongs to. |
name |
Yes | Name of the Sandbox VM. Unique within the project. |
region |
Yes | Region to create the Sandbox VM in. |
tags |
No | Tags to attach to the Sandbox VM. |
instance_type |
No | Defaults to n1-highcpu-2, the only size. |
vpc_id |
No | VPC to place the Sandbox VM in. If you leave it out, the platform chooses one. See VPC placement. |
The request returns 202 with an operation. Its resource_id is the ID of the
new Sandbox VM:
{ "id": "0d3c2b1a-9f8e-4d7c-8b6a-5f4e3d2c1b0a", "project_id": "123e4567-e89b-12d3-a456-426614174000", "status": "pending", "type": "create", "kind": "sandbox_vm", "resource_id": "7c9e6679-7425-40de-944b-e07fc1f90ae7", "created_at": "2026-11-30T10:00:00Z", "updated_at": "2026-11-30T10:00:00Z"}2. Wait for the operation to complete
Section titled “2. Wait for the operation to complete”Poll GET /v1/operations/{operation_id} until its status is done. This
helper keeps polling while the operation is pending or running. It stops
with an error if the operation fails, the request fails (for example, because
the key expired), or the response has any other status:
wait_for_operation() { local response op_status while true; do response=$(curl -sS --fail-with-body \ "https://api.nirvanalabs.io/v1/operations/$1" \ -H "Authorization: Bearer $NIRVANA_API_KEY") || { echo "$response" >&2 return 1 } op_status=$(jq -r '.status // empty' <<<"$response") echo "operation $1: ${op_status:-unexpected response}" case "$op_status" in done) return 0 ;; pending | running) sleep 5 ;; *) echo "$response" >&2 return 1 ;; esac done}
export SANDBOX_VM_ID=$(jq -r .resource_id create.json)wait_for_operation "$(jq -r .id create.json)"Then check the Sandbox VM. It is ready for sandboxes when its status is
ready and its power_state is running:
curl -sS "https://api.nirvanalabs.io/v1/sandbox_vms/$SANDBOX_VM_ID" \ -H "Authorization: Bearer $NIRVANA_API_KEY" | jq '{status, power_state, vpc_id}'3. Create a sandbox with the OpenSandbox SDK
Section titled “3. Create a sandbox with the OpenSandbox SDK”Install the OpenSandbox Python SDK:
python3 -m venv .venv && .venv/bin/pip install opensandboxSave this as quickstart.py. It creates a sandbox on the Sandbox VM, runs a
command in it, and deletes the sandbox:
import asyncioimport osfrom datetime import timedelta
from opensandbox import Sandboxfrom opensandbox.config import ConnectionConfig
async def main() -> None: config = ConnectionConfig( domain="api.nirvanalabs.io", api_key=os.environ["NIRVANA_API_KEY"], protocol="https", # the SDK defaults to http ) sandbox = await Sandbox.create( "python:3.12-slim", connection_config=config, timeout=timedelta(minutes=30), ready_timeout=timedelta(minutes=2), extensions={"nirvana.sandbox_vm_id": os.environ["SANDBOX_VM_ID"]}, ) try: print("sandbox", sandbox.id) execution = await sandbox.commands.run("python3 --version") print(execution.logs.stdout[0].text) finally: # Deletes the sandbox and closes the SDK's connections. await sandbox.destroy()
asyncio.run(main()).venv/bin/python quickstart.pyextensions={"nirvana.sandbox_vm_id": ...} routes the sandbox to your Sandbox
VM. The SDK sends the key in the OPEN-SANDBOX-API-KEY header and adds /v1
to the domain itself. timeout sets when the sandbox expires. The Python SDK
applies its own default timeout when you leave it out.
Other OpenSandbox SDKs work the same way: set the domain to
api.nirvanalabs.io with HTTPS, and pass the same extension.
4. Clean up
Section titled “4. Clean up”The script has already deleted the sandbox. Now delete the Sandbox VM and wait for the operation to finish:
curl -sS -X DELETE "https://api.nirvanalabs.io/v1/sandbox_vms/$SANDBOX_VM_ID" \ -H "Authorization: Bearer $NIRVANA_API_KEY" | tee delete.json
wait_for_operation "$(jq -r .id delete.json)"Deleting a Sandbox VM also deletes every sandbox on it and its disk. A VPC that was created for the Sandbox VM is not deleted. See VPC placement.
Pause, resume and power off
Section titled “Pause, resume and power off”A Sandbox VM has two state fields:
statusis the usual resource status. It isupdatingwhile a pause, resume or restart runs.power_statesays whether its sandboxes can run:running,pausedorpowered_off.
power_state |
The VM | Sandboxes | Billed for |
|---|---|---|---|
running |
Running. | Running and reachable. | vCPU, memory and disk |
paused |
Running, with every sandbox container stopped. | Stopped. Processes and memory are gone. Files and installed packages are kept. | Disk only |
powered_off |
Halted. Only its data disk is kept. | Stopped, as when paused. Files and installed packages are kept on the data disk. | Disk only |
What a pause keeps
Section titled “What a pause keeps”A pause stops every sandbox container on the Sandbox VM. It does not freeze them:
- Kept: files written in the sandbox and packages installed in it. The sandbox keeps its ID.
- Lost: running processes, including commands you started in the sandbox, and everything held in memory.
On resume, each sandbox’s container is started again, which runs its entrypoint again. Start any other processes yourself. If an agent needs to pick up where it left off, have it write its state to files before you pause.
A restart of a running Sandbox VM has the same effect on sandboxes: files are kept, but processes and memory are lost.
Power off
Section titled “Power off”After a Sandbox VM has been paused for an hour, it is powered off. While it is
paused, paused_at and powers_off_at show when it was paused and when it
powers off. Both are null while it runs.
A resume works the same from either state. From powered_off, it boots the VM
first, so it takes longer than a resume from paused.
Billing
Section titled “Billing”Pausing stops compute billing. A paused or powered-off Sandbox VM is billed
only for its data disk, until you resume it or delete it. To see what a running
Sandbox VM costs before you create it, send the same body as the create
request to POST /v1/sandbox_vms/cost.
If your organization is suspended for non-payment, its Sandbox VMs are paused. They stay paused after the organization is reactivated, until you resume them.
VM actions and sandbox actions
Section titled “VM actions and sandbox actions”Pausing, resuming and restarting apply to the whole Sandbox VM and every sandbox on it. You can’t pause or resume an individual sandbox.
VM actions
Section titled “VM actions”Send these to the Nirvana API with the sandbox_vm edit permission. Each one
returns 202 with an operation (type pause, resume, restart or
delete) to poll like the create operation.
| Request | Effect |
|---|---|
POST /v1/sandbox_vms/{sandbox_vm_id}/pause |
Stops every sandbox and stops compute billing. If the Sandbox VM is already paused, nothing changes. |
POST /v1/sandbox_vms/{sandbox_vm_id}/resume |
Starts the sandboxes again, booting the VM first if it is powered off. If the Sandbox VM is already running, nothing changes. |
POST /v1/sandbox_vms/{sandbox_vm_id}/restart |
Restarts a running VM. Sandboxes keep their files but lose their processes and memory. A paused or powered-off Sandbox VM is left as it is; use resume to start it. |
DELETE /v1/sandbox_vms/{sandbox_vm_id} |
Deletes the Sandbox VM, every sandbox on it and its disk. Works whether it is running, paused or powered off. |
A pause, resume or restart sent while another one runs is queued. It runs after
the current one, so you can safely retry these requests. A Sandbox VM that is
being deleted, or has failed, rejects them with 409 and the
SANDBOX_VM_NOT_COMMANDABLE error type.
A delete is accepted only when the Sandbox VM’s status is ready or error.
While it is being created or a pause, resume or restart runs, a delete fails
with 409 and the SANDBOX_VM_NOT_DELETABLE error type. Wait for the
operation to finish and try again.
A resume can fail if the organization used up its sandbox quota while the
Sandbox VM was paused. A resume or restart fails with 402 when billing blocks
new compute.
PATCH /v1/sandbox_vms/{sandbox_vm_id} changes only the name and tags.
Sandbox actions
Section titled “Sandbox actions”These go to the OpenSandbox API at /v1/sandboxes, with the sandbox
permission. They work only while the Sandbox VM is running:
- Create, get and delete a sandbox.
- Get an endpoint for one of a sandbox’s ports.
- Renew a sandbox’s expiration and update its metadata.
While the Sandbox VM is paused or powered off:
- Calls on its sandboxes fail with
409and theSANDBOX_VM_PAUSEDerror type. Errors on/v1/sandboxesuse OpenSandbox’s error shape, so the type is in thecodefield. GET /v1/sandboxesleaves its sandboxes out.
Pausing or resuming a single sandbox
(POST /v1/sandboxes/{sandbox_id}/pause or /resume, or the SDKs’ pause()
and resume()) fails with 409 and the SANDBOX_PAUSE_NOT_SUPPORTED error
type. Pause the Sandbox VM instead.
Networking
Section titled “Networking”VPC placement
Section titled “VPC placement”Every Sandbox VM is placed in a VPC in its project
and region, and stays in it for its whole life. The response’s vpc_id shows
which VPC.
- With
vpc_id: the VPC must bereadyand in the same project and region as the Sandbox VM. - Without
vpc_id: the Sandbox VM goes into the oldest ready VPC in the project and region. If there is none, a new VPC namedsandbox-vms-<region>is created for it.
A VPC created for a Sandbox VM is a normal VPC in your project. It counts against your VPC quota and isn’t deleted with the Sandbox VM. Later Sandbox VMs in the same project and region go into it. You can’t delete a VPC while it holds Sandbox VMs.
The Sandbox VM has a network interface on the VPC’s network. Code in its
sandboxes therefore runs inside that VPC. To keep untrusted code away from your
other resources, give your Sandbox VMs a VPC of their own and pass its ID as
vpc_id.
Endpoint access
Section titled “Endpoint access”To reach a port in a sandbox, request an endpoint as you would on a Sandbox Cluster:
curl "https://api.nirvanalabs.io/v1/sandboxes/{sandbox_id}/endpoints/8000" \ -H "OPEN-SANDBOX-API-KEY: $NIRVANA_API_KEY"On a Sandbox VM, the endpoint is a signed path on the Nirvana API. It has no scheme, and the response has no headers:
{ "endpoint": "api.nirvanalabs.io/v1/sandbox_vm_endpoints/<sandbox_id>/8000/<expires>/<signature>"}Send requests over HTTPS to https:// plus the endpoint, and append the path
you want. The Nirvana API relays them to the sandbox’s port. OpenSandbox SDKs
do this for you, for example with sandbox.get_endpoint(port).
- Treat the endpoint as a secret. The signature in the path is the only credential. Anyone with the URL can reach the port until the endpoint expires. This is what lets a browser open a preview without sending headers.
- Use the endpoint exactly as returned. Don’t build or change its path
segments. Any change to the sandbox ID, port, expiry or signature fails with
403and theINVALID_SANDBOX_ENDPOINT_SIGNATUREerror type. - It expires. By default an endpoint expires when the sandbox does, or
after 1 hour if the sandbox doesn’t expire. Pass
?expires={unix_seconds}to choose a different expiry. An endpoint never lasts more than 24 hours. After it expires, requests fail with403and theSANDBOX_ENDPOINT_EXPIREDerror type. Request a new endpoint. - It works only while the Sandbox VM runs. While the Sandbox VM is paused,
requests fail with
409and theSANDBOX_VM_PAUSEDerror type. After a resume, an endpoint that hasn’t expired works again. - It is served under a path. A web app that loads assets from root-relative
URLs such as
/app.jswon’t find them through the endpoint.
secureAccess can’t be set on a sandbox on a Sandbox VM. A create request that
sets it fails with 400 and the INVALID_SANDBOX_REQUEST error type.
Operations
Section titled “Operations”Create, delete, pause, resume and restart return an operation with kind
sandbox_vm. Its resource_id is the Sandbox VM’s ID. To read the operations
of Sandbox VMs, an API key needs sandbox_vm read on the project.
Versions
Section titled “Versions”Once a Sandbox VM is running, image_version and opensandbox_version show
the versions of the image and the OpenSandbox server it runs. Both are null
until then.