Skip to content

armgit / E2B

Public Imported from GitHub
0

Open-source, secure environment with real-world tools for enterprise-grade agents.

Add docs about filter on Sandbox.list

Jakub Novake855adb38f9c
diff --git a/apps/web/src/app/(docs)/docs/sandbox/list/page.mdx b/apps/web/src/app/(docs)/docs/sandbox/list/page.mdx
index c1b68e288..7a32437f2 100644
--- a/apps/web/src/app/(docs)/docs/sandbox/list/page.mdx
+++ b/apps/web/src/app/(docs)/docs/sandbox/list/page.mdx
@@ -1,3 +1,5 @@
+import Link from 'next/link'
+
# List running sandboxes
You can list all running sandboxes using the `Sandbox.list()` method.
@@ -58,3 +60,51 @@ Running sandbox started at: 2024-10-15 21:13:07.311861+00:00
Running sandbox template id: 3e4rngfa34txe0gxc1zf
```
</CodeGroup>
+
+
+## Filtering sandboxes
+<Note>
+ This feature is in private beta.
+</Note>
+
+You can filter sandboxes by:
+- <Link href="/docs/sandbox/metadata">Metadata</Link> key value pairs
+
+This can be useful when you have a large number of sandboxes and want to find only specific ones.
+
+<CodeGroup>
+```js
+import { Sandbox } from '@e2b/code-interpreter'
+
+// Create sandbox with metadata.
+const sandbox = await Sandbox.create({
+ metadata: {
+ env: 'dev', // $HighlightLine
+ app: 'my-app', // $HighlightLine
+ userId: '123', // $HighlightLine
+ },
+})
+
+// List running sandboxes filtered by metadata.
+const runningSandboxes = await Sandbox.list({
+ filters: { userId: '123', env: 'dev' } // $HighlightLine
+})
+```
+```python
+from e2b_code_interpreter import Sandbox
+
+# Create sandbox with metadata.
+sandbox = Sandbox(
+ metadata={
+ "env": "dev", # $HighlightLine
+ "app": "my-app", # $HighlightLine
+ "user_id": "123", # $HighlightLine
+ },
+)
+
+# List running sandboxes filtered by metadata.
+running_sandboxes = Sandbox.list(filters={
+ "userId": "123", "env": "dev" # $HighlightLine
+})
+```
+</CodeGroup>
diff --git a/apps/web/src/app/(docs)/docs/sandbox/metadata/page.mdx b/apps/web/src/app/(docs)/docs/sandbox/metadata/page.mdx
index 0db8a8e01..bb150e2e9 100644
--- a/apps/web/src/app/(docs)/docs/sandbox/metadata/page.mdx
+++ b/apps/web/src/app/(docs)/docs/sandbox/metadata/page.mdx
@@ -1,3 +1,5 @@
+import Link from 'next/link'
+
# Sandbox metadata
Metadata is a way to attach arbitrary key-value pairs for a sandbox.
@@ -9,6 +11,8 @@ This is useful in various scenarios, for example:
You specify metadata when creating a sandbox and can access it later through listing running sandboxes with `Sandbox.list()` method.
+You can also filter sandboxes by metadata, you can find more about it <Link href="/docs/sandbox/list#filtering-sandboxes">here</Link>
+
<CodeGroup>
```js
import { Sandbox } from '@e2b/code-interpreter'