Create a Sandbox
This guide shows you how to create an Agent Sandbox using the REST API.
Prerequisites
Section titled “Prerequisites”- A sandbox cluster with
status
ready, and its ID. - A Nirvana API key with the
sandboxeditpermission on the cluster’s project. See Connect to a Sandbox Cluster. - curl, an HTTP client or an OpenSandbox SDK.
Create a sandbox
Section titled “Create a sandbox”Send a POST request to /v1/sandboxes with your container image, entrypoint,
resource limits and the sandbox cluster ID in extensions. The sandbox is
ready within seconds.
curl -X POST https://api.nirvanalabs.io/v1/sandboxes \ -H "Content-Type: application/json" \ -H "OPEN-SANDBOX-API-KEY: $NIRVANA_API_KEY" \ -d '{ "image": {"uri": "python:3.12-slim"}, "entrypoint": ["python3", "-m", "http.server", "8000"], "resourceLimits": {"cpu": "1", "memory": "1Gi"}, "extensions": { "nirvana.sandbox_cluster_id": "123e4567-e89b-12d3-a456-426614174000" } }'The response includes the sandbox id. Its extensions also carry
nirvana.sandbox_cluster_id and nirvana.region.
Create a sandbox with a persistent volume
Section titled “Create a sandbox with a persistent volume”Add a pvc volume to keep data on block storage. See
Persistence & Storage for the
options.
curl -X POST https://api.nirvanalabs.io/v1/sandboxes \ -H "Content-Type: application/json" \ -H "OPEN-SANDBOX-API-KEY: $NIRVANA_API_KEY" \ -d '{ "image": {"uri": "python:3.12-slim"}, "entrypoint": ["python3", "-m", "http.server", "8000"], "resourceLimits": {"cpu": "2", "memory": "2Gi"}, "volumes": [ { "name": "workspace", "pvc": { "claimName": "agent-workspace", "createIfNotExists": true, "storage": "50Gi" }, "mountPath": "/workspace" } ], "extensions": { "nirvana.sandbox_cluster_id": "123e4567-e89b-12d3-a456-426614174000" } }'Configuration options
Section titled “Configuration options”Container image to run, as a URI such as python:3.12-slim or
node:18-alpine.
Entrypoint
Section titled “Entrypoint”Command to run when the sandbox starts.
Resource limits
Section titled “Resource limits”CPU and memory for the sandbox:
- CPU: cores as a string, such as
"1","2"or"2000m". - Memory: a size such as
"512Mi","1Gi"or"2Gi".
Timeout
Section titled “Timeout”Optional timeout in seconds, after which the sandbox expires. Without it, the
sandbox doesn’t expire. Extend it later with renew-expiration.
Extensions
Section titled “Extensions”nirvana.sandbox_cluster_id(required): ID of the sandbox cluster to run the sandbox on.
Not supported
Section titled “Not supported”snapshotId: creating sandboxes from snapshots.hostandossfsvolumes. Onlypvcvolumes are accepted.
Next steps
Section titled “Next steps”- Access Endpoints: connect to services running in your sandbox.
- Delete: clean up when done.