Skip to main content
Create a new isolated execution environment for running code and managing files.
from gravixlayer import GravixLayer

client = GravixLayer(api_key="YOUR_API_KEY")

# Create a sandbox from a template
sandbox = client.sandbox.sandboxes.create(
    template="python-base-v1",
    timeout=300,  # 5 minutes (default)
)

print(f"Sandbox ID: {sandbox.sandbox_id}")
print(f"Status: {sandbox.status}")
print(f"Template: {sandbox.template}")
print(f"CPU: {sandbox.cpu_count}")
print(f"Memory: {sandbox.memory_mb} MB")

# Clean up when done
client.sandbox.sandboxes.kill(sandbox.sandbox_id)

Request Parameters

ParameterTypeRequiredDescription
templatestringYesTemplate to use (e.g., “python-base-v1”)
timeoutintegerNoTimeout in seconds (default: 300, max: 3600)

Response

{
  "sandbox_id": "550e8400-e29b-41d4-a716-446655440000",
  "template": "python-base-v1",
  "status": "creating",
  "started_at": "2025-01-27T10:30:00Z",
  "timeout_at": "2025-01-27T10:35:00Z",
  "cpu_count": 2,
  "memory_mb": 2048
}

Templates

You need to build a custom template using the TemplateBuilder before creating a sandbox. Templates define the runtime, packages, and resource limits for your environment.

Next Steps

Execute Code

Run Python or JavaScript code in your sandbox

List Sandboxes

View all your sandboxes

Get Sandbox Info

Retrieve detailed sandbox information

Terminate Sandbox

Clean up resources when finished