Sandbox Persistence
Pausing and Resuming Sandboxes
Section titled “Pausing and Resuming Sandboxes”You can pause a running Sandbox by calling the pause
method on the Sandbox
instance. This will save the state of the Sandbox, including the file system and any running processes. Later, you can resume the Sandbox by calling the resume
method:
Tip: Pausing and resuming is only supported on x86 sandboxes. Android sandboxes are not supported.
Note: If you have a service (e.g., a server) running inside the Sandbox and you pause it, the service will become inaccessible from the outside, and all connected clients will be disconnected. When you resume the Sandbox, the service will be available again, but clients will need to reconnect.
Note: Pausing a sandbox takes a few seconds, resuming is almost instant, and a sandbox can be paused for up to 30 days, after which its data is deleted and resuming it will raise a NotFoundException.
from agentbox import Sandbox
# Create a new sandbox
sbx = Sandbox(
api_key="ab_xxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
template="dr68insivc2tac3ox3ts",
timeout=60
)
print('Sandbox created:', sbx.sandbox_id)
# Pause the sandbox
sbx.pause()
print("Sandbox paused:", sbx.sandbox_id)
# Resume the sandbox
resumed_sbx = Sandbox.resume(sbx.sandbox_id)
print("Sandbox resumed:", resumed_sbx.sandbox_id)
from agentbox import AsyncSandbox
async def main():
# Create a new sandbox
sbx = await AsyncSandbox.create(
api_key="ab_xxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
template="dr68insivc2tac3ox3ts",
timeout=60
)
print('Sandbox created:', sbx.sandbox_id)
# Pause the sandbox
await sbx.pause()
print("Sandbox paused:", sbx.sandbox_id)
# Resume the sandbox
resumed_sbx = await AsyncSandbox.resume(sbx.sandbox_id)
print("Sandbox resumed:", resumed_sbx.sandbox_id)