Sandbox persistence is currently in public beta:
- Consider some limitations.
- The persistence is free for all users during the beta.
Sandbox State Transitions
Understanding how sandboxes transition between different states is crucial for managing their lifecycle effectively. Here’s a diagram showing the possible state transitions:
State descriptions
- Running: The sandbox is actively running and can execute code. This is the initial state after creation.
- Paused: The sandbox execution is suspended but its state is preserved.
- Killed: The sandbox is terminated and all resources are released. This is a terminal state.
Changing sandbox’s state
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.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.Listing paused sandboxes
You can list all paused sandboxes by calling theSandbox.list
method and supplying the state
query parameter.
More information about using the method can be found in List Sandboxes.
Removing paused sandboxes
You can remove paused sandboxes by calling thekill
method on the Sandbox instance.
Sandbox’s timeout
When you connect to 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 theSandbox.connect()
/Sandbox.connect()
method like this:
Auto-pause (beta)
Note: Auto-pause is currently in beta and available throughSandbox.betaCreate()
/Sandbox.beta_create()
method.
Sandboxes can now automatically pause after they time out. When a sandbox is paused, it stops consuming compute but preserves its state. The default inactivity timeout is 10 minutes. You can change the timeout by passing the timeoutMs
/timeout
parameter to the Sandbox.connect()
/Sandbox.connect()
method.
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
- Pausing a sandbox takes about 4 seconds per 1 GiB of RAM
- Resuming a sandbox takes about 1 second
- Sandbox can be used up to 30 days
- After 30 days from the initial sandbox create call, the data may be deleted and you will not be able to resume it. Attempting to resume a sandbox that was deleted or does not exist will result in the
NotFoundError
in the JavaScript SDK or theNotFoundException
in the Python SDK
- After 30 days from the initial sandbox create call, the data may be deleted and you will not be able to resume it. Attempting to resume a sandbox that was deleted or does not exist will result in the