Skip to content

Latest commit

 

History

History
131 lines (103 loc) · 4.28 KB

File metadata and controls

131 lines (103 loc) · 4.28 KB

Sandbox persistence

Sandbox persistence is currently in beta with [some limitations](#limitations-while-in-beta).

The persistence is free for all users during the beta.

The sandbox persistence allows you to pause your sandbox and resume it later from the same state it was in when you paused it.

This includes not only state of the sandbox's filesystem but also the sandbox's memory. This means all running processes, loaded variables, data, etc.

Pausing sandbox

When you pause a sandbox, both the sandbox's filesystem and memory state will be saved. This includes all the files in the sandbox's filesystem and all the running processes, loaded variables, data, etc.

```js import { Sandbox } from 'e2b' // or use Code Interpreter: https://github.com/e2b-dev/code-interpreter // import { Sandbox } from '@e2b/code-interpreter' // // 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() // $HighlightLine console.log('Sandbox paused', sandboxId) // $HighlightLine

```python
from e2b import Sandbox
# or use Code Interpreter: https://github.com/e2b-dev/code-interpreter
# from e2b_code_interpreter import Sandbox
#
# or use Desktop: https://github.com/e2b-dev/desktop
# from e2b_desktop import Sandbox

sbx = Sandbox()
print('Sandbox created', sbx.sandbox_id)

# Pause the sandbox
# You can save the sandbox ID in your database
# to resume the sandbox later
sandbox_id = sbx.pause() # $HighlightLine
print('Sandbox paused', sandbox_id) # $HighlightLine

Resuming sandbox

When you resume a sandbox, it will be in the same state it was in when you paused it. This means that all the files in the sandbox's filesystem will be restored and all the running processes, loaded variables, data, etc. will be restored.

```js import { Sandbox } from 'e2b' // or use Code Interpreter: https://github.com/e2b-dev/code-interpreter // import { Sandbox } from '@e2b/code-interpreter' // // 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() console.log('Sandbox paused', sandboxId)

// Resume the sandbox from the same state const sameSbx = await Sandbox.resume(sandboxId) // $HighlightLine console.log('Sandbox resumed', sameSbx.sandboxId) // $HighlightLine

```python
from e2b import Sandbox
# or use Code Interpreter: https://github.com/e2b-dev/code-interpreter
# from e2b_code_interpreter import Sandbox
#
# or use Desktop: https://github.com/e2b-dev/desktop
# from e2b_desktop import Sandbox

sbx = Sandbox()
print('Sandbox created', sbx.sandbox_id)

# Pause the sandbox
# You can save the sandbox ID in your database
# to resume the sandbox later
sandbox_id = sbx.pause()
print('Sandbox paused', sandbox_id)

# Resume the sandbox from the same state
same_sbx = Sandbox.resume(sandbox_id) # $HighlightLine
print('Sandbox resumed', same_sbx.sandbox_id) # $HighlightLine

Sandbox's timeout

When you resume a sandbox, the sandbox's timeout is reset to the default timeout of an E2B sandbox - 5 minutes.

You can pass a custom timeout to the Sandbox.resume() method like this:

```js import { Sandbox } from 'e2b'

const sbx = await Sandbox.resume(sandboxId, { timeoutMs: 60 * 1000 }) // 60 seconds

```python
from e2b import Sandbox

sbx = Sandbox.resume(sandbox_id, timeout=60) # 60 seconds

Network

If you have a service (for example a server) running inside your sandbox and you pause the sandbox, the service won't be accessible from the outside and all the clients will be disconnected. If you resume the sandbox, the service will be accessible again but you need to connect clients again.

Limitations while in beta

  • It takes about 4 seconds per 1 GB RAM to pause the sandbox
  • It takes about 2 seconds to resume the sandbox
    • Soon, this will get to the same speed as calling Sandbox.create()
  • Sandbox can be paused up to 30 days