Saving and Restoring Sandbox Files with Snapshots
Create a snapshot to save workspace files, then use it to create a new sandbox.
Snapshots preserve filesystem contents. They don't preserve running processes, command execution, or memory. Restoring a snapshot creates a new sandbox with a new sandbox ID.
Save a snapshot before stopping the source sandbox or allowing it to expire. Set the snapshot expiration duration to the period for which you need its files.
profile_name="DEFAULT"
region="us-chicago-1"
sandbox_id="SANDBOX_ID"
project_id="PROJECT_OCID"Creating a Snapshot
This example requests a snapshot with a seven-day retention period:
snapshot_id=$(oci --profile "$profile_name" --auth security_token --region "$region" \
generative-ai-sandbox sandbox-snapshot create \
--sandbox-id "$sandbox_id" \
--expiration-duration P7D \
--query 'data.id' --raw-output)Save the snapshot ID. Inspect its lifecycle state before using it as a source:
oci --profile "$profile_name" --auth security_token --region "$region" \
generative-ai-sandbox sandbox-snapshot get \
--snapshot-id "$snapshot_id"Creating a Sandbox from a Snapshot
After snapshot creation completes, create a new sandbox using its ID:
sandbox_id=$(oci --profile "$profile_name" --auth security_token --region "$region" \
generative-ai-sandbox sandbox create-from-snapshot \
--project-id "$project_id" \
--source-snapshot-id "$snapshot_id" \
--display-name restored-sandbox \
--expiration-duration PT30M \
--query 'data.id' --raw-output)Wait for the new sandbox to reach RUNNING. Start any required processes again, and use the new ID for commands and file operations.
Listing and Inspecting Snapshots
List snapshots for a project. Add --sandbox-id to filter by the source sandbox:
oci --profile "$profile_name" --auth security_token --region "$region" \
generative-ai-sandbox sandbox-snapshot list \
--project-id "$project_id" \
--sandbox-id "SOURCE_SANDBOX_ID" \
--limit 25The source sandbox ID is the ID used when creating the snapshot, which can differ from a restored sandbox's ID. Use the get command above to inspect one snapshot.
Deleting a Snapshot
Delete a snapshot when its saved files are no longer needed for creating sandboxes:
oci --profile "$profile_name" --auth security_token --region "$region" \
generative-ai-sandbox sandbox-snapshot delete \
--snapshot-id "$snapshot_id"Review and confirm the CLI deletion prompt.