-
Notifications
You must be signed in to change notification settings - Fork 495
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adds filtering sandboxes by state in the SDKs #564
base: beta
Are you sure you want to change the base?
Changes from all commits
6504900
039b7a3
33f2c07
60a75a8
1f95e44
8c096b1
a90ebc4
76d8a94
5e1c6ab
d688463
6bc1c1b
8b48134
5f0c179
fe1ffa7
5803a4f
1898417
20bb345
a8ec896
f58ad17
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
'@e2b/python-sdk': minor | ||
'e2b': minor | ||
'@e2b/cli': minor | ||
--- | ||
|
||
Adds filtering sandboxes by state in the SDKs and display of the state in the CLI |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -128,6 +128,84 @@ print('Sandbox resumed', same_sbx.sandbox_id) # $HighlightLine | |
``` | ||
</CodeGroup> | ||
|
||
## 4. Listing paused sandboxes | ||
You can list all paused sandboxes by calling the `Sandbox.list` method by supplying the `state` parameter. | ||
|
||
<CodeGroup> | ||
```js | ||
import { Sandbox } from '@e2b/code-interpreter' | ||
// or use Core: https://github.com/e2b-dev/e2b | ||
// import { Sandbox } from 'e2b' | ||
// | ||
// or use Desktop: https://github.com/e2b-dev/desktop | ||
// import { Sandbox } from '@e2b/desktop' | ||
|
||
// List all paused sandboxes | ||
const sandboxes = await Sandbox.list({ state: ['paused'] }) // $HighlightLine | ||
console.log('Paused sandboxes', sandboxes) // $HighlightLine | ||
``` | ||
```python | ||
from e2b import Sandbox | ||
# or use Core: https://github.com/e2b-dev/e2b | ||
# from e2b import Sandbox | ||
# | ||
# or use Desktop: https://github.com/e2b-dev/desktop | ||
# from e2b_desktop import Sandbox | ||
|
||
# List all paused sandboxes | ||
sandboxes = Sandbox.list(state=['paused']) # $HighlightLine | ||
print('Paused sandboxes', sandboxes) # $HighlightLine | ||
``` | ||
</CodeGroup> | ||
|
||
## 5. Removing paused sandboxes | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why is js and python little bit different, also could you unify word There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you give me an example? |
||
|
||
You can remove paused (and running!) sandboxes by calling the `kill` method on the Sandbox instance. | ||
|
||
<CodeGroup> | ||
```js | ||
import { Sandbox } from '@e2b/code-interpreter' | ||
// or use Core: https://github.com/e2b-dev/e2b | ||
// import { Sandbox } from 'e2b' | ||
// | ||
// or use Desktop: https://github.com/e2b-dev/desktop | ||
// import { Sandbox } from '@e2b/desktop' | ||
|
||
const sbx = await Sandbox.create() | ||
console.log('Sandbox created', sbx.sandboxId) | ||
|
||
// Pause the sandbox | ||
// You can save the sandbox ID in your database | ||
// to resume the sandbox later | ||
const sandboxId = await sbx.pause() | ||
|
||
// Remove the sandbox | ||
await sbx.kill() // $HighlightLine | ||
|
||
// Remove sandbox by id | ||
await Sandbox.kill(sandboxId) // $HighlightLine | ||
``` | ||
```python | ||
from e2b import Sandbox | ||
# or use Core: https://github.com/e2b-dev/e2b | ||
# from e2b import Sandbox | ||
# | ||
# or use Desktop: https://github.com/e2b-dev/desktop | ||
# from e2b_desktop import Sandbox | ||
|
||
sbx = Sandbox() | ||
|
||
# Pause the sandbox | ||
sandbox_id = sbx.pause() | ||
|
||
# Remove the sandbox | ||
sbx.kill() # $HighlightLine | ||
|
||
# Remove sandbox by id | ||
Sandbox.kill(sandbox_id) # $HighlightLine | ||
``` | ||
</CodeGroup> | ||
|
||
## Sandbox's timeout | ||
When you resume a sandbox, the sandbox's timeout is reset to the default timeout of an E2B sandbox - 5 minutes. | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mishushakov will deleting paused sandboxes be included in a separate PR? I'm asking because the new docs addition doesn't mention anything about deleting paused sandboxes.
Other than that, this looks good to me on the docs level
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, this will be a separate PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nevermind, I have decided to add it here as well to avoid merge conflicts