[iris]
Concepts

Checkpoint Restore

Roll back a sandbox filesystem to a saved checkpoint

What is Checkpoint Restore?

sandbox.checkpoint.restore(checkpointId) rewinds the sandbox's filesystem to the state captured in a named checkpoint. The same sandbox object is reused — no new sandbox is created.

To create a checkpoint to restore from, see Checkpoints.

// Save current filesystem state
const cp = await sandbox.checkpoint.create({ name: 'baseline' })

// Do something destructive
await sandbox.exec.run('rm -rf /app/data')

// Roll back — same sandbox, filesystem rewound
const result = await sandbox.checkpoint.restore(cp.checkpoint_id)
console.log(`Restored in ${result.restore_duration_ms}ms`)
console.log('Services restarted:', result.started_services)

Checkpoint restore rolls back the filesystem only. In-memory state is not preserved — running processes are stopped and restarted from their on-disk state at the time of the checkpoint. Network connections are not restored.

Response Fields

RestoreResponse fields:

FieldTypeDescription
okbooleantrue if restore completed without errors
restore_duration_msnumberHow long the restore took
started_servicesstring[]Services successfully restarted
stopped_servicesstring[]Services that were stopped
failed_servicesstring[]Services that failed to restart

Retry Loops

Restore is useful when you need to retry an operation from a known-good filesystem state:

const cp = await sandbox.checkpoint.create({ name: 'before-attempt' })

for (let attempt = 0; attempt < 3; attempt++) {
  const result = await sandbox.exec.run('python3 flaky_script.py')

  if (result.ok) break

  if (attempt < 2) {
    // Restore filesystem to the same starting point and retry
    await sandbox.checkpoint.restore(cp.checkpoint_id)
  }
}

Multi-Step Rollback

Checkpoint at each successful step and restore to the last good state on failure:

const checkpoints: string[] = []

for (const step of workflow) {
  const cp = await sandbox.checkpoint.create({ name: step.name })
  checkpoints.push(cp.checkpoint_id)

  const result = await sandbox.exec.run(step.code)

  if (!result.ok) {
    const lastGood = checkpoints[checkpoints.length - 2]
    if (lastGood) await sandbox.checkpoint.restore(lastGood)
    console.error(`Step ${step.name} failed:`, result.stderr)
    break
  }
}

Fork vs Restore — When to Use Each

fork()checkpoint.restore(id)
ResultNew independent sandboxSame sandbox, filesystem rewound
Original sandboxKeeps running unchangedModified in-place
ParallelismMultiple branches at onceSequential — one restore at a time
Use caseParallel experiments, test isolationRetry loops, sequential rollback
ScopeFilesystem copy-on-writeFilesystem rollback
MemoryNot capturedNot captured

On this page