Skip to content
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Monitor sandbox lifecycle events
# Monitor Sandbox Lifecycle Events

The Lifecycle API provides RESTful endpoints to request the latest sandbox lifecycle events. This allows you to track when sandboxes are created, paused, resumed, updated, or killed, along with metadata.
All requests require authentication using your team [API key](/docs/api-key#where-to-find-api-key).
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,254 @@
# Sandbox Lifecycle Webhooks

Webhooks provide a way for notifications to be delivered to an external web server whenever certain sandbox lifecycle events occur.
This allows you to receive real-time updates about sandbox creation, updates, and termination without having to poll the API.
All webhook requests require authentication using your team [API key](/docs/api-key#where-to-find-api-key).

## Webhook Management

### Register Webhook

Register a new webhook to receive sandbox lifecycle events.
The webhook will be registered for the team ID associated with your API key. You will receive webhook notifications for sandbox lifecycle events from sandboxes created by your team.


<CodeGroup>
```js
// Register a new webhook
const resp = await fetch(
'https://api.e2b.app/events/webhooks/sandboxes',
{
method: 'POST',
headers: {
'X-API-Key': E2B_API_KEY,
'Content-Type': 'application/json',
},
body: JSON.stringify({
url: 'https://your-webhook-endpoint.com/webhook',
events: ['create', 'kill', 'update']
}),
}
)

if (resp.status === 201) {
console.log('Webhook registered successfully')
}
```
```python
import requests

# Register a new webhook
resp = requests.post(
"https://api.e2b.app/events/webhooks/sandboxes",
headers={
"X-API-Key": E2B_API_KEY,
"Content-Type": "application/json",
},
json={
"url": "https://your-webhook-endpoint.com/webhook",
"events": ["create", "kill", "update"]
}
)

if resp.status_code == 201:
print("Webhook registered successfully")
```
</CodeGroup>


### Get Webhook Configuration

Retrieve the current webhook configuration for your team.

<CodeGroup>
```js
// Get current webhook configuration
const resp = await fetch(
'https://api.e2b.app/events/webhooks/sandboxes',
{
method: 'GET',
headers: {
'X-API-Key': E2B_API_KEY,
},
}
)
const webhookConfig = await resp.json()
console.log(webhookConfig)
// {
// "teamID": "460355b3-4f64-48f9-9a16-4442817f79f5",
// "url": "https://your-webhook-endpoint.com/webhook",
// "events": ["create", "kill"]
// }

```
```python
import requests

# Get current webhook configuration
resp = requests.get(
"https://api.e2b.app/events/webhooks/sandboxes",
headers={
"X-API-Key": E2B_API_KEY,
}
)
webhook_config = resp.json()

print(webhook_config)
# {
# "teamID": "460355b3-4f64-48f9-9a16-4442817f79f5",
# "url": "https://your-webhook-endpoint.com/webhook",
# "events": ["create", "kill"]
# }
```
</CodeGroup>

### Update Webhook Configuration
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
### Update Webhook Configuration
### Update webhook configuration


Update an existing webhook configuration. The update will replace the previous configuration fields with provided fields.

<CodeGroup>
```js
// Update webhook configuration
const resp = await fetch(
'https://api.e2b.app/events/webhooks/sandboxes',
{
method: 'PATCH',
headers: {
'X-API-Key': E2B_API_KEY,
'Content-Type': 'application/json',
},
body: JSON.stringify({
url: 'https://your-updated-webhook-endpoint.com/webhook',
events: ['create', 'kill']
}),
}
)

if (resp.status === 200) {
console.log('Webhook updated successfully')
}
```
```python
import requests

# Update webhook configuration
resp = requests.patch(
"https://api.e2b.app/events/webhooks/sandboxes",
headers={
"X-API-Key": E2B_API_KEY,
"Content-Type": "application/json",
},
json={
"url": "https://your-updated-webhook-endpoint.com/webhook",
"events": ["create", "kill"]
}
)

if resp.status_code == 200:
print("Webhook updated successfully")
```
</CodeGroup>

### Delete Webhook
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
### Delete Webhook
### Delete webhook


Unregister the webhook.

<CodeGroup>
```js
// Delete webhook configuration
const resp = await fetch(
'https://api.e2b.app/events/webhooks/sandboxes',
{
method: 'DELETE',
headers: {
'X-API-Key': E2B_API_KEY,
},
}
)

if (resp.status === 200) {
console.log('Webhook deleted successfully')
}
```
```python
import requests

# Delete webhook configuration
resp = requests.delete(
"https://api.e2b.app/events/webhooks/sandboxes",
headers={
"X-API-Key": E2B_API_KEY,
}
)

if resp.status_code == 200:
print("Webhook deleted successfully")
```
</CodeGroup>

### Test Webhook
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
### Test Webhook
### Test webhook


Send a test webhook to verify your endpoint is working correctly.

<CodeGroup>
```js
// Test webhook endpoint
const resp = await fetch(
'https://api.e2b.app/events/webhooks/sandboxes/test',
{
method: 'POST',
headers: {
'X-API-Key': E2B_API_KEY,
},
}
)

if (resp.status === 200) {
console.log('Test webhook sent successfully')
}
```
```python
import requests

# Test webhook endpoint
resp = requests.post(
"https://api.e2b.app/events/webhooks/sandboxes/test",
headers={
"X-API-Key": E2B_API_KEY,
}
)

if resp.status_code == 200:
print("Test webhook sent successfully")
```
</CodeGroup>

## Webhook Payload

When a webhook is triggered, your endpoint will receive a POST request with a JSON payload containing the sandbox event data. The payload structure matches the event format from the API:

```json
{
"eventCategory": "lifecycle",
"eventData": null,
"eventLabel": "create",
"sandboxBuildId": "a979a14b-bdcc-49e6-bc04-1189fc9fe7c2",
"sandboxExecutionId": "1dae9a1c-9957-4ce7-a236-a99d5779aadf",
"sandboxId": "your-sandbox-id",
"sandboxTeamId": "${E2B_TEAM_ID}",
"sandboxTemplateId": "rki5dems9wqfm4r03t7g",
"timestamp": "2025-08-06T20:59:24Z"
}
```

## Available Event Types

The following event types can be subscribed to via webhooks:

- `create` - Sandbox creation
- `kill` - Sandbox termination
- `update` - Sandbox configuration updates
- `pause` - Sandbox pausing
- `resume` - Sandbox resuming


4 changes: 4 additions & 0 deletions apps/web/src/components/Navigation/routes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,10 @@ export const docRoutes: NavGroup[] = [
title: 'Lifecycle events API',
href: '/docs/sandbox/lifecycle-events-api',
},
{
title: 'Lifecycle events webhooks',
href: '/docs/sandbox/lifecycle-events-webhooks',
},
{
title: 'Persistence',
href: '/docs/sandbox/persistence',
Expand Down