Skip to main content
Sandboxes stay active as long as there’s an active connection to them, typically through a WebSocket connection. When a browser tab becomes inactive, the WebSocket should disconnect after some time, but this behavior depends on the specific browser implementation.
You can also use process keep-alive to keep the sandbox running when you launch a process, even if there isn’t an active connection to it.
There are no built-in stop or start functions available in the SDKs to manage standby mode. This means you’ll need to rely on other approaches to better control when sandboxes remain active:
  1. Hide iframe when tab is inactive Use JavaScript events to detect when a user is not active on the tab:
    • Listen for tab visibility events that indicate when the user switches away from your tab
    • When the user becomes inactive, hide the iframe containing the sandbox preview
    • Show the iframe again when the user returns to the tab
  2. Implement auto-disconnect on tab switch Some browsers (like Chrome) may keep WebSockets alive even when tabs are inactive to improve performance. You can implement an auto-disconnect feature that:
    • Detects when users switch tabs
    • Automatically disconnects the WebSocket connection
    • Reconnects when the user returns
  3. Use activity-based timeouts Set up a timer system in your interface that:
    • Monitors user activity (typing, interactions, etc.)
    • Hides the preview after a period of inactivity
    • Prompts the user to confirm they’re still using the sandbox
You can use the SDKs from the frontend if you have the right headers set on the session. Use the sandbox.sessions.create function to manage sessions. Here is an example of auto disconnect on tab switch with Vite through a plugin:
The code below is illustrative and not intended for production use.
Last modified on March 26, 2026