Skip to main content
Terminate a running sandbox to free up resources and manage costs effectively.
curl -X DELETE https://api.gravixlayer.com/v1/agents/sandboxes/550e8400-e29b-41d4-a716-446655440000 \
  -H "Authorization: Bearer YOUR_API_KEY"

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:
# Download important files
curl -X GET "https://api.gravixlayer.com/v1/agents/sandboxes/550e8400-e29b-41d4-a716-446655440000/download?path=/home/user/results.csv" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -o results.csv

# Save application state
curl -X POST https://api.gravixlayer.com/v1/agents/sandboxes/550e8400-e29b-41d4-a716-446655440000/code/run \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "code": "import json\nstate = {\"status\": \"completed\", \"timestamp\": \"2025-01-27T10:30:00Z\"}\nwith open(\"/home/user/state.json\", \"w\") as f: json.dump(state, f)",
    "language": "python"
  }'

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