> ## Documentation Index
> Fetch the complete documentation index at: https://docs.hopx.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Delete Sandbox

> Permanently delete a sandbox and free its resources using the HopX Control Plane API. Remove sandboxes when no longer needed to free up resources and manage costs. Learn how to use DELETE /v1/sandboxes/:id endpoint to permanently delete sandboxes and clean up resources. Includes request examples and cleanup best practices.

Delete a sandbox to permanently destroy it and free all allocated resources. This action cannot be undone.

## Endpoint

```
DELETE /v1/sandboxes/:id
```

## Request

### Headers

```
Authorization: Bearer $HOPX_API_KEY
```

### Path Parameters

| Parameter | Type   | Description          |
| --------- | ------ | -------------------- |
| `id`      | string | Sandbox ID to delete |

### Example Request

```bash theme={null}
curl -X DELETE https://api.hopx.dev/v1/sandboxes/sandbox_abc123xyz \
  -H "Authorization: Bearer $HOPX_API_KEY"
```

## Response

### Success (200 OK)

```json theme={null}
{
  "status": "deleted",
  "id": "sandbox_abc123xyz",
  "request_id": "req_abc123"
}
```

### Response Fields

| Field        | Type   | Description              |
| ------------ | ------ | ------------------------ |
| `status`     | string | Always `"deleted"`       |
| `id`         | string | Deleted sandbox ID       |
| `request_id` | string | Request ID for debugging |

## Status Codes

| Code  | Description                  |
| ----- | ---------------------------- |
| `200` | Sandbox deleted successfully |
| `401` | Authentication required      |
| `404` | Sandbox not found            |

## Errors

### Sandbox Not Found (404)

```json theme={null}
{
  "error": "Sandbox not found",
  "code": "RESOURCE_NOT_FOUND",
  "request_id": "req_abc123"
}
```

**Cause:** The sandbox ID doesn't exist or belongs to another organization.

**Fix:** Verify the sandbox ID is correct. List your sandboxes using `GET /v1/sandboxes` to find valid IDs.

## Important Notes

<Warning>
  Deleting a sandbox is **permanent and irreversible**. All data, files, and state in the sandbox will be lost. Make sure to save any important data before deleting.
</Warning>

* **Immediate deletion** - The sandbox is destroyed immediately upon successful deletion
* **Resource cleanup** - All allocated resources (vCPU, memory, disk) are freed
* **VM Agent API** - The sandbox's VM Agent API endpoint becomes unavailable immediately
* **No recovery** - Deleted sandboxes cannot be recovered

## Use Cases

### Clean Up After Task Completion

```bash theme={null}
# Execute your task
# ... code execution ...

# Delete when done
curl -X DELETE https://api.hopx.dev/v1/sandboxes/sandbox_abc123xyz \
  -H "Authorization: Bearer $HOPX_API_KEY"
```

### Delete All Stopped Sandboxes

```bash theme={null}
#!/bin/bash
# Get all stopped sandboxes
STOPPED=$(curl -s "https://api.hopx.dev/v1/sandboxes?status=stopped" \
  -H "Authorization: Bearer $HOPX_API_KEY" | \
  jq -r '.data[].id')

# Delete each one
for ID in $STOPPED; do
  curl -X DELETE "https://api.hopx.dev/v1/sandboxes/$ID" \
    -H "Authorization: Bearer $HOPX_API_KEY"
  echo "Deleted $ID"
done
```

### Delete Sandbox with Verification

```bash theme={null}
#!/bin/bash
SANDBOX_ID="sandbox_abc123xyz"

# Verify sandbox exists
STATUS=$(curl -s "https://api.hopx.dev/v1/sandboxes/$SANDBOX_ID" \
  -H "Authorization: Bearer $HOPX_API_KEY" | jq -r '.status')

if [ "$STATUS" != "null" ]; then
  # Delete it
  curl -X DELETE "https://api.hopx.dev/v1/sandboxes/$SANDBOX_ID" \
    -H "Authorization: Bearer $HOPX_API_KEY"
  echo "Sandbox $SANDBOX_ID deleted"
else
  echo "Sandbox not found"
fi
```

## Related

* **SDK**: [sandbox.kill()](/sdk/python/sandbox#kill) - Python SDK method
* [CLI Sandbox Commands](/cli/commands/sandbox) - Manage sandboxes from CLI

## Next Steps

* **[List Sandboxes](/api/control-plane/list-sandboxes)** - View all your sandboxes
* **[Create Sandbox](/api/control-plane/create-sandbox)** - Create a new sandbox
* **[Get Sandbox](/api/control-plane/get-sandbox)** - Retrieve sandbox information
