contree-sdk 0.5.1 to start from an available Alpine image, write a file, and read it after saving a checkpoint. The default lazy session can reuse a running VM between commands; taking a snapshot saves its files and stops that VM.
1
Create a project and configure access
Create an API key and copy the project ID as described in Set up access. Install uv if needed, then run:Use Python 3.12 for this example. The pins pair SDK 0.5.1 with client 0.6.0 for reproducible setup. The SDK also accepts a saved CLI profile; see connection sources.
2
Save and reuse a file
Create Run it:Expected output includes an immutable image UUID followed by:The example uses the existing
quickstart.py:alpine:latest tag. Tags can move; use an immutable image UUID when reproducibility matters. See image discovery for available images.session.run() returns an InstanceResult directly. Process status is in result.state; captured streams provide .as_text() and .as_bytes(). The snapshot returns a history entry whose image_uuid identifies the saved filesystem.Commands before a snapshot can share processes and memory. Here, snapshot() stops the VM, so the subsequent cat starts a new VM from the saved files. Normal context exit saves pending changes and closes the client and store created by the factory. An exception discards changes since the last completed snapshot.3
Handle failures before continuing
Check
result.state.exit_code before using command output. A nonzero exit code is a workload result; it does not undo files changed by that command. Check it before saving or continuing. Use a known-good checkpoint for recovery.An operation failure raises FailedOperationError; cancellation raises InterruptedError. A failed or cancelled wait attempts remote cancellation. Keep the operation ID when available and inspect its status before retrying uncertain work. See Troubleshooting.session_type=ContreeSession for a separate VM and automatic save after each command. That mode supports disposable=True per command; the lazy session does not. See Sessions and execution modes.