Skip to main content
The from_snippet() method allows you to create a new sandbox that shares the same file system and state as a previously created sandbox, using its unique snippet ID. This is particularly useful when you’ve created a sandbox with should_backup_filesystem=True and want to resume work later without losing any files or progress.

async from_snippet(playground_snippet_id: str) -> None

Description:
Recreates a sandbox using the same file system as a previous sandbox session identified by its snippet ID.

Parameters:
ParameterTypeRequiredDescription
playground_snippet_idstrYesThe snippet ID returned from a previous create() call (use result['playgroundSnippetId']).

Returns:
None: Resolves when the sandbox has successfully connected and restored the previous environment.

Example

import asyncio
from fermion_sandbox import Sandbox

async def main():
    # --- Session 1: Create a persistent sandbox ---
    sandbox1 = Sandbox(api_key="your-api-key")

    # Create a sandbox with persistent filesystem
    result = await sandbox1.create(should_backup_filesystem=True)
    snippet_id = result['playgroundSnippetId']

    # Write a file to the sandbox
    await sandbox1.write_file(path="/home/damner/data.txt", content="saved")

    # Disconnect but keep the filesystem backed up
    await sandbox1.disconnect()

    # --- Session 2: Resume using the same filesystem ---
    sandbox2 = Sandbox(api_key="your-api-key")

    # Reconnect using the saved snippet ID
    await sandbox2.from_snippet(playground_snippet_id=snippet_id)

    # Read the previously saved file
    response = await sandbox2.get_file("/home/damner/data.txt")
    file_content = response.text
    print(file_content)  # Output: "saved"

asyncio.run(main())