mimobox_vm/lib.rs
1#![cfg_attr(docsrs, feature(doc_cfg))]
2#![warn(missing_docs)]
3
4//! microVM sandbox backend for mimobox.
5//!
6//! This crate provides the microVM isolation layer used by the higher-level mimobox
7//! sandbox APIs. It exposes configuration, lifecycle management, guest command
8//! execution, file transfer, controlled HTTP proxying, snapshot serialization, and
9//! optional pooling helpers.
10//!
11//! The main entry point is [`MicrovmSandbox`], which implements
12//! [`mimobox_core::Sandbox`]. Linux builds with the `kvm` feature use `KvmBackend`
13//! for the underlying VM lifecycle. Other platforms keep the public API available
14//! but return [`MicrovmError::UnsupportedPlatform`] for KVM-only operations.
15//!
16//! Snapshot support is split into [`MicrovmSnapshot`] for self-describing in-memory
17//! snapshots and file-backed [`mimobox_core::SandboxSnapshot`] values for fast
18//! restore paths. [`VmPool`] prewarms fully booted VMs, while `RestorePool` keeps
19//! empty VM shells ready for snapshot restoration on supported KVM builds.
20//!
21//! HTTP access from guests is intentionally host-mediated. [`HttpRequest`] values
22//! are validated against `SandboxConfig::allowed_http_domains` and
23//! executed by the host-side proxy rather than by giving the guest direct network
24//! access.
25
26mod guest_file_ops;
27mod http_proxy;
28/// Thread-safe microVM prewarm pool types.
29pub mod pool;
30mod snapshot;
31mod vm;
32mod vm_assets;
33
34#[cfg(all(target_os = "linux", feature = "kvm"))]
35mod kvm;
36#[cfg(all(target_os = "linux", feature = "kvm"))]
37mod restore_pool;
38
39pub use http_proxy::{HttpProxyError, HttpRequest, HttpResponse};
40pub use pool::{PoolError, PooledVm, VmPool, VmPoolConfig, VmPoolStats};
41pub use snapshot::MicrovmSnapshot;
42pub use vm::{
43 GuestCommandResult, GuestExecOptions, GuestFileErrorKind, LifecycleError, MicrovmConfig,
44 MicrovmError, MicrovmSandbox, MicrovmState, StreamEvent,
45};
46pub use vm_assets::{
47 microvm_config_from_assets_dir, microvm_config_from_vm_assets, resolve_vm_assets_dir,
48 vm_assets_dir,
49};
50
51#[cfg(all(target_os = "linux", feature = "kvm"))]
52#[cfg_attr(docsrs, doc(cfg(feature = "kvm")))]
53pub use kvm::{KvmBackend, KvmExitReason, KvmLifecycle, KvmTransport};
54#[cfg(all(target_os = "linux", feature = "kvm"))]
55#[cfg_attr(docsrs, doc(cfg(feature = "kvm")))]
56pub use restore_pool::{PooledRestoreVm, RestorePool, RestorePoolConfig, RestorePoolError};