Skip to content

The micro-VM for AI agents — light enough to embed on your laptop, elastic enough to power an agentic cloud.

feat(runtime): add VMM-agnostic full checkpoint export/import placeholders (#3104)

lfld287fa2f524bb98e
diff --git a/docs/reference/rust/README.md b/docs/reference/rust/README.md
index ba42c5467..cf78ed7a3 100644
--- a/docs/reference/rust/README.md
+++ b/docs/reference/rust/README.md
@@ -498,6 +498,21 @@ The shim's configured or inherited `RLIMIT_FSIZE` soft limit can restrict growth
Other engines and remote backends return `Unsupported`; this API is not exposed through REST, CLI or other SDKs.
+#### ExportOptions
+
+`ExportOptions::default()` exports disks only. Set `include_memory: true` or
+use `ExportOptions::full()` to request a full checkpoint. Local full export
+requires a running box and reconnects to a detached VM if needed. It does not
+start an inactive box. The current VMM checkpoint hook is a placeholder and
+returns `Unsupported`. REST export also returns `Unsupported` for full
+checkpoints without sending a request. Import rejects v8 archives and manifests
+carrying memory checkpoint metadata with `Unsupported` as soon as it reads the
+manifest; disk-only archives remain supported through v7.
+
+Rust source migration: replace `ExportOptions {}` with `ExportOptions::default()`
+for disk-only export. If you construct a disk-only `ArchiveManifest` directly,
+set `memory_checkpoint: None`.
+
#### ExecutionsHandle
`LiteBox::executions()` returns an owned, cloneable `ExecutionsHandle` without
diff --git a/sdks/node/src/snapshot_options.rs b/sdks/node/src/snapshot_options.rs
index 8387cd912..1d20cff79 100644
--- a/sdks/node/src/snapshot_options.rs
+++ b/sdks/node/src/snapshot_options.rs
@@ -21,7 +21,7 @@ pub struct JsExportOptions {}
impl From<JsExportOptions> for ExportOptions {
fn from(_js: JsExportOptions) -> Self {
- ExportOptions {}
+ ExportOptions::default()
}
}
diff --git a/sdks/python/src/snapshot_options.rs b/sdks/python/src/snapshot_options.rs
index 65530f1e7..8f8f4181e 100644
--- a/sdks/python/src/snapshot_options.rs
+++ b/sdks/python/src/snapshot_options.rs
@@ -37,7 +37,7 @@ impl PyExportOptions {
impl From<PyExportOptions> for ExportOptions {
fn from(_py: PyExportOptions) -> Self {
- ExportOptions {}
+ ExportOptions::default()
}
}
diff --git a/src/boxlite/src/lib.rs b/src/boxlite/src/lib.rs
index 3846ebbd6..5d24e3547 100644
--- a/src/boxlite/src/lib.rs
+++ b/src/boxlite/src/lib.rs
@@ -55,7 +55,7 @@ pub use disk::DiskInfo;
pub use event_listener::{AuditEvent, AuditEventKind, AuditEventListener, EventListener};
pub use images::ResolvedImage;
pub use litebox::SnapshotHandle;
-pub use litebox::archive::ArchiveManifest;
+pub use litebox::archive::{ArchiveManifest, MemoryCheckpointMetadata};
pub use litebox::snapshot_mgr::SnapshotInfo;
pub use litebox::{
AttachOptions, BoxCommand, CopyOptions, ExecResult, ExecStderr, ExecStdin, ExecStdout,
diff --git a/src/boxlite/src/litebox/archive.rs b/src/boxlite/src/litebox/archive.rs
index c00cc6995..a07cae471 100644
--- a/src/boxlite/src/litebox/archive.rs
+++ b/src/boxlite/src/litebox/archive.rs
@@ -40,6 +40,9 @@ pub(crate) const FRACTIONAL_CPUS_ARCHIVE_VERSION: u32 = 6;
/// Managed and typed mounts require a local volume-capable importer.
pub(crate) const MANAGED_MOUNTS_ARCHIVE_VERSION: u32 = 7;
+/// Reserved archive version for full checkpoints that include VM memory.
+pub(crate) const MEMORY_CHECKPOINT_ARCHIVE_VERSION: u32 = 8;
+
/// Maximum archive version this build can import.
pub(crate) const MAX_SUPPORTED_VERSION: u32 = MANAGED_MOUNTS_ARCHIVE_VERSION;
@@ -71,6 +74,13 @@ pub(crate) fn archive_version_for_options(options: &crate::runtime::options::Box
}
}
+/// VMM-independent metadata for a full memory checkpoint.
+#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
+pub struct MemoryCheckpointMetadata {
+ /// Size of the captured VM memory in bytes.
+ pub memory_size_bytes: u64,
+}
+
/// Archive manifest stored as `manifest.json` inside exported archives.
///
/// v1: plain tar, no checksums
@@ -80,9 +90,10 @@ pub(crate) fn archive_version_for_options(options: &crate::runtime::options::Box
/// v5: `ports` carry publication semantics (automatic host port, bind IP)
/// v6: fractional `box_options.cpus` requires host CPU bandwidth enforcement
/// v7: managed/typed mounts require local volume-capable resolution
+/// v8: reserved for full memory checkpoints (not importable yet)
#[derive(Debug, Serialize, Deserialize)]
pub struct ArchiveManifest {
- /// Archive format version (1 through 7).
+ /// Archive format version.
pub version: u32,
/// Original box name (optional, may be renamed on import).
pub box_name: Option<String>,
@@ -92,6 +103,9 @@ pub struct ArchiveManifest {
#[serde(default, skip_serializing_if = "Option::is_none")]
#[serde(deserialize_with = "crate::runtime::cpu_count::deserialize_options")]
pub box_options: Option<crate::runtime::options::BoxOptions>,
+ /// Present only for full memory checkpoints.
+ #[serde(default, skip_serializing_if = "Option::is_none")]
+ pub memory_checkpoint: Option<MemoryCheckpointMetadata>,
/// SHA-256 checksum of the guest rootfs disk.
///
/// Always empty: the guest rootfs is no longer bundled in archives (it ships
@@ -161,8 +175,18 @@ fn append_archive_files<W: Write>(
/// Zstd magic bytes: `0x28B52FFD` (little-endian in file).
const ZSTD_MAGIC: [u8; 4] = [0x28, 0xB5, 0x2F, 0xFD];
-/// Extract an archive, detecting format via magic bytes (zstd or plain tar).
+#[cfg(test)]
pub(crate) fn extract_archive(archive_path: &Path, dest_dir: &Path) -> BoxliteResult<()> {
+ extract_archive_with_manifest(archive_path, dest_dir, |_| Ok(()))
+}
+
+/// Extract a zstd or plain tar archive. Validate each top-level manifest as
+/// soon as it is unpacked, before advancing to the next member.
+pub(crate) fn extract_archive_with_manifest(
+ archive_path: &Path,
+ dest_dir: &Path,
+ validate_manifest: impl FnMut(&Path) -> BoxliteResult<()>,
+) -> BoxliteResult<()> {
use std::io::Read;
let mut file = std::fs::File::open(archive_path).map_err(|e| {
@@ -195,9 +219,9 @@ pub(crate) fn extract_archive(archive_path: &Path, dest_dir: &Path) -> BoxliteRe
if magic == ZSTD_MAGIC {
let decoder = zstd::Decoder::new(file)
.map_err(|e| BoxliteError::Storage(format!("Failed to create zstd decoder: {}", e)))?;
- unpack_file_members(decoder, dest_dir)
+ unpack_file_members(decoder, dest_dir, validate_manifest)
} else {
- unpack_file_members(file, dest_dir)
+ unpack_file_members(file, dest_dir, validate_manifest)
}
}
@@ -233,7 +257,13 @@ fn carries_file_contents(entry_type: tar::EntryType) -> bool {
/// member. Member *names* are deliberately not filtered — archives written
/// before the guest rootfs became a shared base image carry a third member that
/// the importer ignores, and rejecting it would strand them.
-fn unpack_file_members<R: std::io::Read>(reader: R, dest_dir: &Path) -> BoxliteResult<()> {
+fn unpack_file_members<R: std::io::Read>(
+ reader: R,
+ dest_dir: &Path,
+ mut validate_manifest: impl FnMut(&Path) -> BoxliteResult<()>,
+) -> BoxliteResult<()> {
+ use std::path::Component;
+
let mut archive = tar::Archive::new(reader);
let entries = archive
.entries()
@@ -255,9 +285,20 @@ fn unpack_file_members<R: std::io::Read>(reader: R, dest_dir: &Path) -> BoxliteR
)));
}
- entry
+ let unpacked = entry
.unpack_in(dest_dir)
.map_err(|e| BoxliteError::Storage(format!("Failed to extract archive: {}", e)))?;
+ // unpack_in already skips paths with '..' and strips root and '.'
+ // components. Match the resulting name, not the raw tar path.
+ if unpacked
+ && entry
+ .path()?
+ .components()
+ .filter(|part| matches!(part, Component::Normal(_)))
+ .eq(Path::new(MANIFEST_FILENAME).components())
+ {
+ validate_manifest(&dest_dir.join(MANIFEST_FILENAME))?;
+ }
}
Ok(())
@@ -335,6 +376,35 @@ mod tests {
use super::*;
use tempfile::tempdir;
+ #[test]
+ fn memory_checkpoint_manifest_round_trips_without_changing_v7_json() {
+ let legacy = serde_json::json!({
+ "version": 7,
+ "box_name": null,
+ "image": "alpine:latest",
+ "guest_disk_checksum": "",
+ "container_disk_checksum": "",
+ "exported_at": "2026-07-26T00:00:00Z"
+ });
+ let mut manifest: ArchiveManifest = serde_json::from_value(legacy.clone()).unwrap();
+ assert_eq!(manifest.memory_checkpoint, None);
+ assert_eq!(serde_json::to_value(&manifest).unwrap(), legacy);
+
+ manifest.version = MEMORY_CHECKPOINT_ARCHIVE_VERSION;
+ manifest.memory_checkpoint = Some(MemoryCheckpointMetadata {
+ memory_size_bytes: 512 * 1024 * 1024,
+ });
+ let encoded = serde_json::to_value(&manifest).unwrap();
+ assert_eq!(encoded["version"], 8);
+ assert_eq!(
+ encoded["memory_checkpoint"]["memory_size_bytes"],
+ 536_870_912
+ );
+ let decoded: ArchiveManifest = serde_json::from_value(encoded).unwrap();
+ assert_eq!(decoded.version, manifest.version);
+ assert_eq!(decoded.memory_checkpoint, manifest.memory_checkpoint);
+ }
+
/// An export must not be readable by an importer that would drop part of
/// its configuration: capability policies are stamped v4, published ports
/// v5, fractional CPUs v6, ordinary boxes v3.
diff --git a/src/boxlite/src/litebox/box_impl.rs b/src/boxlite/src/litebox/box_impl.rs
index 987a3f8ac..cbea5be7b 100644
--- a/src/boxlite/src/litebox/box_impl.rs
+++ b/src/boxlite/src/litebox/box_impl.rs
@@ -806,6 +806,19 @@ impl BoxImpl {
.await
}
+ /// Caller holds lifecycle admission. Reattach to a running VM if needed, never boot one.
+ pub(super) async fn capture_memory_checkpoint(
+ &self,
+ dest_dir: &std::path::Path,
+ ) -> BoxliteResult<()> {
+ let live = self.existing_live_state_locked().await?;
+ let handler = live
+ .handler
+ .lock()
+ .map_err(|e| BoxliteError::Internal(format!("handler lock poisoned: {e}")))?;
+ handler.capture_memory_checkpoint(dest_dir)
+ }
+
pub(crate) async fn metrics(&self) -> BoxliteResult<BoxMetrics> {
// Check if box is stopped before proceeding (via stop() or runtime shutdown)
if self.shutdown_token.is_cancelled() {
@@ -1953,7 +1966,9 @@ mod tests {
use crate::litebox::config::ContainerRuntimeConfig;
use crate::net::{NetworkBackendConfig, NetworkBackendFactory};
use crate::runtime::id::BoxIDMint;
- use crate::runtime::options::{BoxOptions, BoxliteOptions, PortProtocol, PortSpec, RootfsSpec};
+ use crate::runtime::options::{
+ BoxOptions, BoxliteOptions, ExportOptions, PortProtocol, PortSpec, RootfsSpec,
+ };
use crate::runtime::rt_impl::RuntimeImpl;
use crate::runtime::types::{ContainerID, PublishedPort};
use crate::util::{PidFileWriter, PidRecord, ShimPidRecord, is_process_alive};
@@ -2020,6 +2035,136 @@ mod tests {
}
}
+ #[test]
+ fn default_vmm_memory_checkpoint_is_unsupported() {
+ let error = InfoTestHandler(0)
+ .capture_memory_checkpoint(std::path::Path::new("unused"))
+ .unwrap_err();
+ assert!(matches!(error, BoxliteError::Unsupported(message)
+ if message == "full memory checkpoint capture is not supported by this VMM backend"));
+ }
+
+ struct CheckpointTestHandler {
+ expected_temp_root: std::path::PathBuf,
+ captured_dir: Arc<std::sync::Mutex<Option<std::path::PathBuf>>>,
+ succeeds: bool,
+ }
+
+ impl CheckpointTestHandler {
+ fn install(
+ fixture: &mut StartFixture,
+ succeeds: bool,
+ ) -> Arc<std::sync::Mutex<Option<std::path::PathBuf>>> {
+ let box_impl = Arc::get_mut(&mut fixture.box_impl).unwrap();
+ let captured_dir = Arc::new(std::sync::Mutex::new(None));
+ *box_impl.live.get_mut().unwrap().handler.get_mut().unwrap() = Box::new(Self {
+ expected_temp_root: box_impl.runtime.layout.temp_dir(),
+ captured_dir: Arc::clone(&captured_dir),
+ succeeds,
+ });
+ captured_dir
+ }
+ }
+
+ impl VmmHandler for CheckpointTestHandler {
+ fn stop(&mut self) -> BoxliteResult<()> {
+ Ok(())
+ }
+
+ fn metrics(&self) -> BoxliteResult<VmmMetrics> {
+ Ok(VmmMetrics::default())
+ }
+
+ fn is_running(&self) -> bool {
+ true
+ }
+
+ fn pid(&self) -> u32 {
+ 0
+ }
+
+ fn capture_memory_checkpoint(&self, dest_dir: &std::path::Path) -> BoxliteResult<()> {
+ assert!(dest_dir.is_dir());
+ assert!(dest_dir.starts_with(&self.expected_temp_root));
+ *self.captured_dir.lock().unwrap() = Some(dest_dir.to_path_buf());
+ if self.succeeds {
+ std::fs::write(dest_dir.join("memory"), b"checkpoint").unwrap();
+ Ok(())
+ } else {
+ Err(BoxliteError::Unsupported("checkpoint test handler".into()))
+ }
+ }
+ }
+
+ #[tokio::test]
+ async fn full_checkpoint_export_requires_running_box() {
+ let fixture = running_box_for_start_test(Arc::new(StartGate::default())).await;
+ let mut state = fixture.box_impl.state.read().clone();
+ state.status = BoxStatus::Stopped;
+ fixture
+ .box_impl
+ .runtime
+ .box_manager
+ .save_box(fixture.box_impl.id(), &state)
+ .unwrap();
+ let error = fixture
+ .box_impl
+ .export_box(ExportOptions::full(), fixture._temp_dir.path())
+ .await
+ .unwrap_err();
+ assert!(matches!(error, BoxliteError::InvalidState(message)
+ if message == "full checkpoint export requires a running box"));
+ }
+
+ #[tokio::test]
+ async fn full_checkpoint_export_routes_to_vmm_handler() {
+ let mut fixture = running_box_for_start_test(Arc::new(StartGate::default())).await;
+ CheckpointTestHandler::install(&mut fixture, false);
+ let dest = fixture._temp_dir.path().join("checkpoint.boxlite");
+ let error = fixture
+ .box_impl
+ .export_box(ExportOptions::full(), &dest)
+ .await
+ .unwrap_err();
+ assert!(matches!(error, BoxliteError::Unsupported(message)
+ if message == "checkpoint test handler"));
+ }
+
+ #[tokio::test]
+ async fn full_checkpoint_export_rejects_cancelled_shutdown_token() {
+ let mut fixture = running_box_for_start_test(Arc::new(StartGate::default())).await;
+ let captured_dir = CheckpointTestHandler::install(&mut fixture, false);
+ fixture.box_impl.shutdown_token.cancel();
+ let dest = fixture.box_impl.runtime.layout.temp_dir();
+ let error = fixture
+ .box_impl
+ .export_box(ExportOptions::full(), &dest)
+ .await
+ .unwrap_err();
+ assert!(
+ matches!(&error, BoxliteError::Stopped(message)
+ if message == "Handle invalidated after stop(). Use runtime.get() to get a new handle."),
+ "unexpected error: {error:?}"
+ );
+ assert!(captured_dir.lock().unwrap().is_none());
+ }
+
+ #[tokio::test]
+ async fn full_checkpoint_export_fails_closed_when_handler_succeeds() {
+ let mut fixture = running_box_for_start_test(Arc::new(StartGate::default())).await;
+ let captured_dir = CheckpointTestHandler::install(&mut fixture, true);
+ let dest = fixture._temp_dir.path().join("checkpoint.boxlite");
+ let error = fixture
+ .box_impl
+ .export_box(ExportOptions::full(), &dest)
+ .await
+ .unwrap_err();
+ assert!(matches!(error, BoxliteError::Unsupported(message)
+ if message == "full memory checkpoint archive creation is not supported"));
+ let captured_dir = captured_dir.lock().unwrap().take().expect("handler called");
+ assert!(!captured_dir.exists());
+ }
+
struct StartGate {
calls: AtomicUsize,
should_fail: AtomicBool,
diff --git a/src/boxlite/src/litebox/clone_export.rs b/src/boxlite/src/litebox/clone_export.rs
index 1db71c24c..921ba027d 100644
--- a/src/boxlite/src/litebox/clone_export.rs
+++ b/src/boxlite/src/litebox/clone_export.rs
@@ -171,9 +171,36 @@ impl BoxImpl {
pub(crate) async fn export_box(
&self,
- _options: crate::runtime::options::ExportOptions,
+ options: crate::runtime::options::ExportOptions,
dest: &std::path::Path,
) -> BoxliteResult<crate::runtime::options::BoxArchive> {
+ if options.include_memory {
+ return self
+ .with_disk_admission(self.with_operation(async {
+ if self.shutdown_token.is_cancelled() {
+ return Err(BoxliteError::Stopped(
+ "Handle invalidated after stop(). Use runtime.get() to get a new handle."
+ .into(),
+ ));
+ }
+ if self.state.read().status != BoxStatus::Running {
+ return Err(BoxliteError::InvalidState(
+ "full checkpoint export requires a running box".into(),
+ ));
+ }
+ let temp_dir = tempfile::tempdir_in(self.runtime.layout.temp_dir())
+ .map_err(|e| {
+ BoxliteError::Storage(format!("Failed to create temp directory: {}", e))
+ })?;
+ self.capture_memory_checkpoint(temp_dir.path()).await?;
+ // A successful capture still cannot be packaged by this placeholder.
+ Err(BoxliteError::Unsupported(
+ "full memory checkpoint archive creation is not supported".into(),
+ ))
+ }))
+ .await;
+ }
+
let t0 = Instant::now();
self.with_disk_admission(async {
let box_home = self.config.box_home.clone();
@@ -307,6 +334,7 @@ fn do_export_finalize(
box_name: config_name.map(|s| s.to_string()),
image,
box_options: Some(config_options.clone()),
+ memory_checkpoint: None,
guest_disk_checksum: String::new(),
container_disk_checksum,
exported_at: chrono::Utc::now().to_rfc3339(),
diff --git a/src/boxlite/src/rest/litebox.rs b/src/boxlite/src/rest/litebox.rs
index db2a721c6..439d47ffd 100644
--- a/src/boxlite/src/rest/litebox.rs
+++ b/src/boxlite/src/rest/litebox.rs
@@ -650,6 +650,11 @@ impl BoxBackend for RestBox {
options: ExportOptions,
dest: &Path,
) -> BoxliteResult<crate::runtime::options::BoxArchive> {
+ if options.include_memory {
+ return Err(BoxliteError::Unsupported(
+ "full memory checkpoint export is not supported over REST export".into(),
+ ));
+ }
self.client.require_export_enabled().await?;
let box_id = self.box_id_str();
@@ -1433,6 +1438,22 @@ mod tests {
};
use tokio_tungstenite::tungstenite::http::{HeaderName, HeaderValue};
+ #[tokio::test]
+ async fn full_checkpoint_export_is_rejected_before_http() {
+ use futures::FutureExt;
+
+ let listener = TcpListener::bind(("127.0.0.1", 0)).await.unwrap();
+ let remote = rest_box_for(listener.local_addr().unwrap().port(), "checkpoint-box");
+ let error = remote
+ .export_box(ExportOptions::full(), Path::new("unused.boxlite"))
+ .now_or_never()
+ .expect("full checkpoint rejection must not wait for HTTP")
+ .unwrap_err();
+ assert!(matches!(error, BoxliteError::Unsupported(message)
+ if message == "full memory checkpoint export is not supported over REST export"));
+ assert!(listener.accept().now_or_never().is_none());
+ }
+
/// A tunnel target as SDK callers write it.
const LOCAL_3000: &str = "127.0.0.1:3000";
diff --git a/src/boxlite/src/runtime/import.rs b/src/boxlite/src/runtime/import.rs
index 6116b9eb2..905d5c0d9 100644
--- a/src/boxlite/src/runtime/import.rs
+++ b/src/boxlite/src/runtime/import.rs
@@ -8,8 +8,8 @@ use boxlite_shared::errors::{BoxliteError, BoxliteResult};
use crate::disk::constants::filenames as disk_filenames;
use crate::litebox::LiteBox;
use crate::litebox::archive::{
- ArchiveManifest, MANIFEST_FILENAME, MAX_SUPPORTED_VERSION, PUBLISHED_PORTS_ARCHIVE_VERSION,
- extract_archive, move_file, sha256_file,
+ ArchiveManifest, MANIFEST_FILENAME, MAX_SUPPORTED_VERSION, MEMORY_CHECKPOINT_ARCHIVE_VERSION,
+ PUBLISHED_PORTS_ARCHIVE_VERSION, extract_archive_with_manifest, move_file, sha256_file,
};
use crate::runtime::advanced_options::SecurityOptions;
use crate::runtime::options::{
@@ -144,18 +144,14 @@ fn extract_and_validate(
let temp_dir = tempfile::tempdir_in(layout.temp_dir())
.map_err(|e| BoxliteError::Storage(format!("Failed to create temp directory: {}", e)))?;
- extract_archive(archive_path, temp_dir.path())?;
-
- let manifest_path = temp_dir.path().join(MANIFEST_FILENAME);
- if !manifest_path.exists() {
- return Err(BoxliteError::Storage(
- "Invalid archive: manifest.json not found".to_string(),
- ));
- }
-
- let manifest_json = std::fs::read_to_string(&manifest_path)?;
- let manifest: ArchiveManifest = serde_json::from_str(&manifest_json)
- .map_err(|e| BoxliteError::Storage(format!("Invalid manifest: {}", e)))?;
+ let mut manifest = None;
+ extract_archive_with_manifest(archive_path, temp_dir.path(), |path| {
+ manifest = Some(read_disk_only_manifest(path)?);
+ Ok(())
+ })?;
+ let manifest = manifest.ok_or_else(|| {
+ BoxliteError::Storage(format!("Invalid archive: {MANIFEST_FILENAME} not found"))
+ })?;
if manifest.version > MAX_SUPPORTED_VERSION {
return Err(BoxliteError::Storage(format!(
@@ -186,6 +182,19 @@ fn extract_and_validate(
Ok((manifest, temp_dir))
}
+fn read_disk_only_manifest(path: &Path) -> BoxliteResult<ArchiveManifest> {
+ let json = std::fs::read_to_string(path)?;
+ let manifest: ArchiveManifest = serde_json::from_str(&json)
+ .map_err(|e| BoxliteError::Storage(format!("Invalid manifest: {e}")))?;
+ if manifest.version == MEMORY_CHECKPOINT_ARCHIVE_VERSION || manifest.memory_checkpoint.is_some()
+ {
+ return Err(BoxliteError::Unsupported(
+ "importing full memory checkpoint archives is not supported by this VMM backend".into(),
+ ));
+ }
+ Ok(manifest)
+}
+
/// Validate disk security and move disks into box_home/disks/.
fn install_disks(temp_dir: &Path, box_home: &Path) -> BoxliteResult<()> {
// Security: the disk about to become a box's own must be a file this
@@ -274,6 +283,7 @@ mod tests {
box_name: None,
image: "alpine:latest".to_string(),
box_options: Some(options),
+ memory_checkpoint: None,
guest_disk_checksum: String::new(),
container_disk_checksum: String::new(),
exported_at: "2026-07-26T00:00:00Z".to_string(),
@@ -543,6 +553,7 @@ mod tests {
advanced,
..Default::default()
}),
+ memory_checkpoint: None,
guest_disk_checksum: String::new(),
container_disk_checksum: String::new(),
exported_at: "2026-01-01T00:00:00Z".into(),
@@ -604,6 +615,85 @@ mod tests {
"the error must say the disk is not a usable qcow2, got: {error}"
);
}
+ #[test]
+ fn full_checkpoint_archives_are_unsupported() {
+ use crate::litebox::archive::{MemoryCheckpointMetadata, build_zstd_tar_archive};
+ use crate::runtime::layout::FilesystemLayout;
+
+ let dir = TempDir::new().unwrap();
+ let layout = FilesystemLayout::new(dir.path().join("home"), Default::default());
+ std::fs::create_dir_all(layout.temp_dir()).unwrap();
+ let manifest_path = dir.path().join(MANIFEST_FILENAME);
+ let disk_path = dir.path().join("disk");
+ let archive_path = dir.path().join("checkpoint.boxlite");
+ std::fs::write(&disk_path, b"test disk").unwrap();
+ let metadata = MemoryCheckpointMetadata {
+ memory_size_bytes: 4096,
+ };
+ for (version, memory_checkpoint) in
+ [(8, Some(metadata.clone())), (8, None), (7, Some(metadata))]
+ {
+ let mut manifest = v3_manifest(BoxOptions::default());
+ manifest.version = version;
+ manifest.memory_checkpoint = memory_checkpoint;
+ std::fs::write(&manifest_path, serde_json::to_vec(&manifest).unwrap()).unwrap();
+ build_zstd_tar_archive(&archive_path, &manifest_path, &disk_path, 1).unwrap();
+ let error = extract_and_validate(&archive_path, &layout).unwrap_err();
+ assert!(matches!(error, BoxliteError::Unsupported(_)), "{error:?}");
+ }
+ }
+
+ #[test]
+ fn full_checkpoint_import_skips_corrupt_member_after_manifest() {
+ use crate::litebox::archive::MemoryCheckpointMetadata;
+ use crate::runtime::layout::FilesystemLayout;
+
+ let dir = TempDir::new().unwrap();
+ let layout = FilesystemLayout::new(dir.path().join("home"), Default::default());
+ std::fs::create_dir_all(layout.temp_dir()).unwrap();
+ let archive_path = dir.path().join("checkpoint.boxlite");
+
+ let metadata = MemoryCheckpointMetadata {
+ memory_size_bytes: 4096,
+ };
+ for (version, memory_checkpoint, full) in [
+ (MEMORY_CHECKPOINT_ARCHIVE_VERSION, None, true),
+ (7, Some(metadata), true),
+ (7, None, false),
+ ] {
+ let mut manifest = v3_manifest(BoxOptions::default());
+ manifest.version = version;
+ manifest.memory_checkpoint = memory_checkpoint;
+ let json = serde_json::to_vec(&manifest).unwrap();
+
+ let mut builder = tar::Builder::new(Vec::new());
+ let mut header = tar::Header::new_gnu();
+ header.set_mode(0o644);
+ header.set_size(json.len() as u64);
+ builder
+ .append_data(&mut header, MANIFEST_FILENAME, json.as_slice())
+ .unwrap();
+ // A nonzero but invalid tar header must fail if extraction advances.
+ builder.get_mut().extend([0xff; 512]);
+ let tar = builder.into_inner().unwrap();
+ let compressed = zstd::encode_all(tar.as_slice(), 1).unwrap();
+
+ for archive in [&tar, &compressed] {
+ std::fs::write(&archive_path, archive).unwrap();
+ let error = extract_and_validate(&archive_path, &layout).unwrap_err();
+ if full {
+ assert!(matches!(error, BoxliteError::Unsupported(_)), "{error:?}");
+ } else {
+ assert!(
+ matches!(&error, BoxliteError::Storage(message)
+ if message.contains("Failed to read archive member")),
+ "{error:?}"
+ );
+ }
+ }
+ }
+ }
+
#[test]
fn fractional_cpus_archive_versions_and_legacy_options() {
use crate::litebox::archive::build_zstd_tar_archive;
@@ -615,7 +705,7 @@ mod tests {
std::fs::write(&container_path, b"test disk").unwrap();
let manifest_path = dir.path().join(MANIFEST_FILENAME);
let archive_path = dir.path().join("box.boxlite");
- for version in [1, 2, 3, 4, 5, 6, 7, 8] {
+ for version in [1, 2, 3, 4, 5, 6, 7, 9] {
let mut manifest = v3_manifest(BoxOptions {
cpus: Some(if version == 6 { 1.5 } else { 2.0 }),
..Default::default()
@@ -626,6 +716,7 @@ mod tests {
let result = extract_and_validate(&archive_path, &layout);
if version > crate::litebox::archive::MAX_SUPPORTED_VERSION {
let error = result.unwrap_err();
+ assert!(matches!(error, BoxliteError::Storage(_)));
assert!(error.to_string().contains(&format!("version {version}")));
} else {
assert_eq!(
@@ -677,6 +768,7 @@ mod required_import_safety_tests {
secrets: vec![secret],
..Default::default()
}),
+ memory_checkpoint: None,
guest_disk_checksum: String::new(),
container_disk_checksum: sha256_file(&disk).unwrap(),
exported_at: "2026-11-10T00:00:00Z".into(),
@@ -774,6 +866,7 @@ mod required_import_safety_tests {
)],
..Default::default()
}),
+ memory_checkpoint: None,
guest_disk_checksum: String::new(),
container_disk_checksum: sha256_file(&disk).unwrap(),
exported_at: "2026-11-15T00:00:00Z".into(),
diff --git a/src/boxlite/src/runtime/options.rs b/src/boxlite/src/runtime/options.rs
index 5e018b6cf..ec76b1964 100644
--- a/src/boxlite/src/runtime/options.rs
+++ b/src/boxlite/src/runtime/options.rs
@@ -1666,9 +1666,21 @@ impl BoxArchive {
#[derive(Debug, Clone, Default)]
pub struct SnapshotOptions {}
-/// Forward-compatible options for exporting a box archive.
-#[derive(Debug, Clone, Default)]
-pub struct ExportOptions {}
+/// Options for exporting a box archive. The default exports disks only.
+#[derive(Debug, Clone, Default, PartialEq, Eq)]
+pub struct ExportOptions {
+ /// Request a full checkpoint including VM memory. Currently unsupported.
+ pub include_memory: bool,
+}
+
+impl ExportOptions {
+ /// Request a full checkpoint instead of a disk-only archive.
+ pub fn full() -> Self {
+ Self {
+ include_memory: true,
+ }
+ }
+}
/// Forward-compatible options for cloning a box.
#[derive(Debug, Clone, Default)]
@@ -1682,6 +1694,12 @@ mod tests {
ContainerCapabilities, NetworkRateLimit, SecurityOptions, SecurityOptionsBuilder,
};
+ #[test]
+ fn export_options_default_to_disk_only() {
+ assert!(!ExportOptions::default().include_memory);
+ assert!(ExportOptions::full().include_memory);
+ }
+
/// The type decides whose storage `source` names, so only the two exact
/// spellings parse; a near miss is an error naming what is accepted.
#[test]
diff --git a/src/boxlite/src/vmm/controller/handler.rs b/src/boxlite/src/vmm/controller/handler.rs
index 63afe7d8f..2cba7d35e 100644
--- a/src/boxlite/src/vmm/controller/handler.rs
+++ b/src/boxlite/src/vmm/controller/handler.rs
@@ -1,7 +1,7 @@
//! VmmHandler - Runtime operations on a running VM.
use super::VmmMetrics;
-use boxlite_shared::BoxliteResult;
+use boxlite_shared::errors::{BoxliteError, BoxliteResult};
/// Trait for runtime operations on a running VM.
///
@@ -19,6 +19,13 @@ pub trait VmmHandler: Send {
/// Stop the VM.
fn stop(&mut self) -> BoxliteResult<()>;
+ /// Capture VM memory for a full checkpoint in the destination directory.
+ fn capture_memory_checkpoint(&self, _dest_dir: &std::path::Path) -> BoxliteResult<()> {
+ Err(BoxliteError::Unsupported(
+ "full memory checkpoint capture is not supported by this VMM backend".into(),
+ ))
+ }
+
/// Get VM metrics (CPU, memory, disk usage).
fn metrics(&self) -> BoxliteResult<VmmMetrics>;
diff --git a/src/boxlite/tests/detach.rs b/src/boxlite/tests/detach.rs
index 83bd3bcb9..4661aa39e 100644
--- a/src/boxlite/tests/detach.rs
+++ b/src/boxlite/tests/detach.rs
@@ -5,8 +5,9 @@
mod common;
+use boxlite::BoxliteError;
use boxlite::litebox::BoxCommand;
-use boxlite::runtime::options::BoxliteOptions;
+use boxlite::runtime::options::{BoxliteOptions, ExportOptions};
use boxlite::runtime::types::BoxStatus;
use boxlite::util::{PidFileReader, is_process_alive};
use common::TestRuntime as BoxliteRuntime;
@@ -315,10 +316,22 @@ async fn detached_box_recoverable_after_restart() {
);
assert!(info.pid.is_some(), "Recovered box should have PID");
- // Should be able to stop it
let handle = runtime.get(&box_id).await.unwrap().unwrap();
+ let export_dir = tempfile::tempdir().unwrap();
+ // The new handle must reattach on its first live operation, not require
+ // a start or exec before reaching the backend checkpoint hook.
+ let result = handle
+ .export(ExportOptions::full(), export_dir.path())
+ .await;
handle.stop().await.unwrap();
+ let error = result.unwrap_err();
+ assert!(
+ matches!(&error, BoxliteError::Unsupported(message)
+ if message == "full memory checkpoint capture is not supported by this VMM backend"),
+ "unexpected full export error: {error:?}"
+ );
+
let info = runtime
.get_info(&box_id)
.await