Skip to main content
The fromSnippet() method allows you to create a new sandbox with same file system as previous sandbox using its unique snippet ID. This is useful when you’ve created a sandbox with shouldBackupFilesystem: true and want to resume work without losing files or progress.

fromSnippet(playgroundSnippetId)

Description: Creates a new sandbox with same file system as previous sandbox using its snippet ID. Parameters:
ParameterTypeRequiredDescription
playgroundSnippetIdstringYesThe snippet ID returned from a previous create() call
Returns: Promise<void> - Resolves when connection is established Example:
// Session 1: Create persistent sandbox
const snippetId = await sandbox1.create({
  shouldBackupFilesystem: true
})
await sandbox1.writeFile({ path: '/home/damner/data.txt', content: 'saved' })
await sandbox1.disconnect()

// Session 2: Create a new sandbox with same file system as previous sandbox
const sandbox2 = new Sandbox({ apiKey: 'key' })
await sandbox2.fromSnippet(snippetId)
const file = await sandbox2.getFile('/home/damner/data.txt')
console.log(await file.text()) // 'saved'