Skip to main content

disconnect()

The disconnect() method gracefully terminates your active sandbox session by closing the WebSocket connection and releasing all associated resources. This ensures that all running processes are stopped, the session is closed cleanly, and the container is freed up for reuse.

async disconnect() -> None

Description:
Gracefully terminates your active sandbox session and releases all underlying resources.

Parameters:
None

Returns:
None: Resolves when disconnection and cleanup are complete.

Example

import asyncio
from fermion_sandbox import Sandbox

async def main():
    # Initialize and create a new sandbox
    sandbox = Sandbox(api_key="your-api-key")
    await sandbox.create(should_backup_filesystem=False)

    # Perform your tasks
    result = await sandbox.run_command(cmd="python3", args=["--version"])
    print("Python version:", result.stdout)

    # Always clean up when finished
    await sandbox.disconnect()
    print("Sandbox disconnected successfully.")

asyncio.run(main())