Skip to main content
Terminate a running sandbox to free up resources and manage costs effectively.
from gravixlayer import GravixLayer

client = GravixLayer(api_key="YOUR_API_KEY")

# Terminate a sandbox by ID
client.sandbox.sandboxes.kill("your-sandbox-id-here")

Response

{
  "message": "Sandbox terminated successfully",
  "sandbox_id": "550e8400-e29b-41d4-a716-446655440000"
}

When to Terminate

Manual termination scenarios:
  • Task completion - When your processing is finished
  • Resource optimization - To free up unused resources
  • Cost management - To avoid unnecessary charges
  • Error recovery - When sandbox is in an unrecoverable state
Automatic termination occurs when:
  • Timeout reached - Exceeds configured timeout limit
  • Resource limits - CPU or memory usage exceeds safe limits
  • System maintenance - During scheduled maintenance windows

Pre-termination Checklist

Before terminating, ensure you’ve saved important data:
from gravixlayer import GravixLayer

client = GravixLayer(api_key="YOUR_API_KEY")
sandbox_id = "your-sandbox-id"

# Read important files before terminating
result = client.sandbox.sandboxes.read_file(sandbox_id, path="/home/user/results.csv")
print(result.content)

# Save application state
client.sandbox.sandboxes.run_code(
    sandbox_id,
    code='import json; state = {"status": "completed"}; open("/home/user/state.json", "w").write(json.dumps(state))',
    language="python",
)

# Now safe to terminate
client.sandbox.sandboxes.kill(sandbox_id)

Error Handling

Sandbox Not Found (404):
{
  "error": {
    "code": "sandbox_not_found",
    "message": "Sandbox not found"
  }
}
Already Terminated (400):
{
  "error": {
    "code": "invalid_state",
    "message": "Sandbox is already terminated"
  }
}

Next Steps

Create Sandbox

Create new sandboxes

List Sandboxes

View and manage all your sandboxes

Get Sandbox Info

Monitor sandbox information

Execute Code

Run code in new sandboxes