Open-source, secure environment with real-world tools for enterprise-grade agents.
Python agentaiai-agentai-agentscode-interpretercopilotdevelopmentdevtoolsgptgpt-4javascriptllmnextjsopenaipythonreactsoftwaretypescript
Update sandbox lifecycle docs with REST API (#856)
0diva6073cede119
diff --git a/apps/web/src/app/(docs)/docs/sandbox/lifecycle-events-api/page.mdx b/apps/web/src/app/(docs)/docs/sandbox/lifecycle-events-api/page.mdxnew file mode 100644index 000000000..86376c6ac--- /dev/null+++ b/apps/web/src/app/(docs)/docs/sandbox/lifecycle-events-api/page.mdx@@ -0,0 +1,148 @@+# 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).++Query Parameters:+- `offset` (optional): Number of events to skip (default: 0, min: 0)+- `limit` (optional): Number of events to return (default: 10, min: 1, max: 100)+- `orderAsc` (optional): Sort order - true for ascending, false for descending (default: false)+++<CodeGroup>+```js+import { Sandbox } from '@e2b/code-interpreter'++const sbx = await Sandbox.create()++// Get the latest events for a specific sandbox+const resp1 = await fetch(+ `https://api.e2b.app/events/sandboxes/${sbx.id}`,+ {+ method: 'GET',+ headers: {+ 'X-API-Key': E2B_API_KEY,+ },+ }+)+const sandboxEvents = await resp1.json()++// Get the latest 10 events for all sandboxes associated with the team+const resp2 = await fetch(+ 'https://api.e2b.app/events/sandboxes?limit=10',+ {+ method: 'GET',+ headers: {+ 'X-API-Key': E2B_API_KEY,+ },+ }+)+const teamSandboxEvents = await resp2.json()++console.log(teamSandboxEvents)++// [+// {+// "eventCategory": "lifecycle",+// "eventData": null,+// "eventLabel": "kill",+// "sandboxBuildId": "a979a14b-bdcc-49e6-bc04-1189fc9fe7c2",+// "sandboxExecutionId": "1dae9e1c-9957-4ce7-a236-a99d5779aadf",+// "sandboxId": "${SANDBOX_ID}",+// "sandboxTeamId": "460355b3-4f64-48f9-9a16-4442817f79f5",+// "sandboxTemplateId": "rki5dems9wqfm4r03t7g",+// "timestamp": "2025-08-06T20:59:36Z"+// },+// {+// "eventCategory": "lifecycle",+// "eventData": {+// "set_timeout": "2025-08-06T20:59:59Z"+// },+// "eventLabel": "update",+// "sandboxBuildId": "a979a14b-bdcc-49e6-bc04-1189fc9fe7c2",+// "sandboxExecutionId": "1dae9e1c-9957-4ce7-a236-a99d5779aadf",+// "sandboxId": "${SANDBOX_ID}",+// "sandboxTeamId": "460355b3-4f64-48f9-9a16-4442817f79f5",+// "sandboxTemplateId": "rki5dems9wqfm4r03t7g",+// "timestamp": "2025-08-06T20:59:29Z"+// },+// [...]+// {+// "eventCategory": "lifecycle",+// "eventData": null,+// "eventLabel": "create",+// "sandboxBuildId": "a979a14b-bdcc-49e6-bc04-1189fc9fe7c2",+// "sandboxExecutionId": "1dae9e1c-9957-4ce7-a236-a99d5779aadf",+// "sandboxId": "${SANDBOX_ID}",+// "sandboxTeamId": "460355b3-4f64-48f9-9a16-4442817f79f5",+// "sandboxTemplateId": "rki5dems9wqfm4r03t7g",+// "timestamp": "2025-08-06T20:59:24Z"+// }+// ]+```+```python+import requests+from e2b_code_interpreter import Sandbox++sbx = Sandbox()++# Get the latest events for a specific sandbox+resp1 = requests.get(+ f"https://api.e2b.app/events/sandboxes/{sbx.sandbox_id}",+ headers={+ "X-API-Key": E2B_API_KEY,+ }+)+sandbox_events = resp1.json()++# Get the latest 10 events for all sandboxes associated with the team+resp2 = requests.get(+ "https://api.e2b.app/events/sandboxes?limit=10",+ headers={+ "X-API-Key": E2B_API_KEY,+ }+)+team_sandbox_events = resp2.json()++print(team_sandbox_events)++# [+# {+# "eventCategory": "lifecycle",+# "eventData": null,+# "eventLabel": "kill",+# "sandboxBuildId": "a979a14b-bdcc-49e6-bc04-1189fc9fe7c2",+# "sandboxExecutionId": "1dae9e1c-9957-4ce7-a236-a99d5779aadf",+# "sandboxId": "${SANDBOX_ID}",+# "sandboxTeamId": "460355b3-4f64-48f9-9a16-4442817f79f5",+# "sandboxTemplateId": "rki5dems9wqfm4r03t7g",+# "timestamp": "2025-08-06T20:59:36Z"+# },+# {+# "eventCategory": "lifecycle",+# "eventData": {+# "set_timeout": "2025-08-06T20:59:59Z"+# },+# "eventLabel": "update",+# "sandboxBuildId": "a979a14b-bdcc-49e6-bc04-1189fc9fe7c2",+# "sandboxExecutionId": "1dae9e1c-9957-4ce7-a236-a99d5779aadf",+# "sandboxId": "${SANDBOX_ID}",+# "sandboxTeamId": "460355b3-4f64-48f9-9a16-4442817f79f5",+# "sandboxTemplateId": "rki5dems9wqfm4r03t7g",+# "timestamp": "2025-08-06T20:59:29Z"+# },+# [...]+# {+# "eventCategory": "lifecycle",+# "eventData": null,+# "eventLabel": "create",+# "sandboxBuildId": "a979a14b-bdcc-49e6-bc04-1189fc9fe7c2",+# "sandboxExecutionId": "1dae9e1c-9957-4ce7-a236-a99d5779aadf",+# "sandboxId": "${SANDBOX_ID}",+# "sandboxTeamId": "460355b3-4f64-48f9-9a16-4442817f79f5",+# "sandboxTemplateId": "rki5dems9wqfm4r03t7g",+# "timestamp": "2025-08-06T20:59:24Z"+# }+# ]+```+</CodeGroup>diff --git a/apps/web/src/components/Navigation/routes.tsx b/apps/web/src/components/Navigation/routes.tsxindex 4fb85fc93..3d537b5e8 100644--- a/apps/web/src/components/Navigation/routes.tsx+++ b/apps/web/src/components/Navigation/routes.tsx@@ -282,6 +282,10 @@ export const docRoutes: NavGroup[] = [title: 'Lifecycle',href: '/docs/sandbox',},+ {+ title: 'Lifecycle events API',+ href: '/docs/sandbox/lifecycle-events-api',+ },{title: 'Persistence',href: '/docs/sandbox/persistence',