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.

from_snippet(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
snippet_idstrYesThe snippet ID returned from a previous create() call.

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

Example

from fermion_sandbox import Sandbox

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

# Create a sandbox with persistent filesystem
snippet_id = sandbox1.create(should_backup_filesystem=True)

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

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

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

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

# Read the previously saved file
file_content = sandbox2.get_file("~/data.txt")
print(file_content)  # Output: "saved"