Skip to content

Commit

Permalink
Add docs about filter on Sandbox.list (#544)
Browse files Browse the repository at this point in the history
  • Loading branch information
mlejva authored Jan 18, 2025
2 parents 7beccd7 + fb89e96 commit 2f22248
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
50 changes: 50 additions & 0 deletions apps/web/src/app/(docs)/docs/sandbox/list/page.mdx
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import Link from 'next/link'

# List running sandboxes

You can list all running sandboxes using the `Sandbox.list()` method.
Expand Down Expand Up @@ -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. The filtering is performed on the server side.

<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>
5 changes: 5 additions & 0 deletions apps/web/src/app/(docs)/docs/sandbox/metadata/page.mdx
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import Link from 'next/link'

# Sandbox metadata

Metadata is a way to attach arbitrary key-value pairs for a sandbox.
Expand Down Expand Up @@ -47,3 +49,6 @@ running_sandboxes = Sandbox.list()
print(running_sandboxes[0].metadata)
```
</CodeGroup>

## Filtering sandboxes by metadata
You can also filter sandboxes by metadata, you can find more about it <Link href="/docs/sandbox/list#filtering-sandboxes">here</Link>.

0 comments on commit 2f22248

Please sign in to comment.