Skip to main content

Snapshots

Snapshots capture VM disk state plus snapshot metadata so new VMs can boot from a prebuilt environment in milliseconds.

Why use snapshots

  • Fast cold starts -- boot with dependencies already installed.
  • Reproducibility -- launch the same environment repeatedly.
  • Custom base images -- build from any OCI/Docker image, then reuse.

Snapshot creation modes

You can create snapshots in two ways:

  1. From a running VM with POST /v1/vms/{vm_id}/snapshot.
  2. From an OCI image with POST /v1/snapshots (async build).

Use VM snapshots when you already configured a live VM. Use OCI snapshots when you want an image-to-snapshot build pipeline.

Create from a running VM

# Create a VM, configure it, then snapshot
instavm create
# ... install packages, configure files via SSH ...
instavm snapshot create <vm_id> --name python-ml-environment

Create from an OCI image

POST /v1/snapshots requires oci_image. Other fields are optional.

FieldRequiredDefault / LimitsNotes
oci_imageYesstringOCI image reference, for example docker.io/library/python:3.11-slim.
nameNonullSnapshot display name.
vcpu_countNo2 (min 1, max 8)vCPU count for build VM.
memory_mbNo512 (min 128, max 8192)Memory for build VM.
typeNouserMust match user or system.
build_argsNonullBuild-time customization object (see below).

Supported build_args fields:

FieldTypeNotes
extra_apt_packagesstringSpace-separated apt package names.
extra_pip_packagesstringSpace-separated pip package names.
extra_npm_packagesstringSpace-separated npm package names.
git_clone_urlstringCloned into /app/repo.
git_clone_branchstringDefaults to repository default branch.
disk_size_gbinteger1-3; default worker behavior is 3 and values above 3 are capped.
envsobjectEnvironment variables as string key-value pairs.
post_build_cmdstringShell command run after package installation.

Example:

instavm snapshot build docker.io/library/python:3.11-slim \
--name python-3.11-data-stack \
--vcpu 2 \
--memory 1024 \
--apt "git ffmpeg" \
--pip "numpy pandas scikit-learn" \
--git-clone https://github.com/example/repo.git \
--git-branch main \
--disk-size 3 \
--env APP_ENV=prod \
--env PYTHONUNBUFFERED=1 \
--run "pip install -r /app/repo/requirements.txt"

Async build behavior

OCI-image snapshot creation is asynchronous. The create call returns a snapshot record immediately. Check status and last_error with client.snapshots.get(...) or client.snapshots.list(...) until build completion.

# Poll build status
instavm snapshot get <snapshot_id> --json

# Watch until status is "ready" or "failed"
watch -n 5 instavm snapshot get <snapshot_id> --json

Snapshot fields you can rely on

Snapshot records include:

  • id
  • name
  • status
  • snapshot_type
  • type
  • source_vm_id
  • oci_image
  • vcpu_count
  • memory_mb
  • size_bytes
  • is_public
  • last_error
  • created_at
  • updated_at

Boot a VM from a snapshot

instavm create --snapshot snap_xyz789

List snapshots

instavm snapshot ls

# Filter by type
instavm snapshot ls --type user

The REST API also supports filtering by type (GET /v1/snapshots?type=user or type=system).

Delete a snapshot

instavm snapshot rm snap_xyz789

Snapshot on terminate

client.vms.update(
vm_id="vm_abc123",
snapshot_on_terminate=True,
snapshot_name="final-state",
)

Next steps