pub struct MicroVmConfig {Show 15 fields
pub log_level: LogLevel,
pub rootfs: Rootfs,
pub num_vcpus: u8,
pub memory_mib: u32,
pub mapped_dirs: Vec<PathPair>,
pub port_map: Vec<PortPair>,
pub scope: NetworkScope,
pub ip: Option<Ipv4Addr>,
pub subnet: Option<Ipv4Network>,
pub rlimits: Vec<LinuxRlimit>,
pub workdir_path: Option<Utf8UnixPathBuf>,
pub exec_path: Utf8UnixPathBuf,
pub args: Vec<String>,
pub env: Vec<EnvPair>,
pub console_output: Option<Utf8UnixPathBuf>,
}Expand description
Configuration for a MicroVm instance.
This struct holds all the settings needed to create and run a MicroVm, including system resources, filesystem configuration, networking, and process execution details.
Rather than creating this directly, use MicroVmConfigBuilder or
MicroVmBuilder for a more ergonomic interface.
§Examples
use microsandbox_core::vm::{MicroVm, MicroVmConfig, Rootfs};
use tempfile::TempDir;
let temp_dir = TempDir::new()?;
let config = MicroVmConfig::builder()
.rootfs(Rootfs::Native(temp_dir.path().to_path_buf()))
.memory_mib(1024)
.exec_path("/bin/echo")
.build();
let vm = MicroVm::from_config(config)?;Fields§
§log_level: LogLevelThe log level to use for the MicroVm.
rootfs: RootfsThe rootfs for the MicroVm.
num_vcpus: u8The number of vCPUs to use for the MicroVm.
memory_mib: u32The amount of memory in MiB to use for the MicroVm.
mapped_dirs: Vec<PathPair>The directories to mount in the MicroVm using virtio-fs. Each PathPair represents a host:guest path mapping.
port_map: Vec<PortPair>The port map to use for the MicroVm.
scope: NetworkScopeThe network scope to use for the MicroVm.
ip: Option<Ipv4Addr>The IP address to use for the MicroVm.
subnet: Option<Ipv4Network>The subnet to use for the MicroVm.
rlimits: Vec<LinuxRlimit>The resource limits to use for the MicroVm.
workdir_path: Option<Utf8UnixPathBuf>The working directory path to use for the MicroVm.
exec_path: Utf8UnixPathBufThe executable path to use for the MicroVm.
args: Vec<String>The arguments to pass to the executable.
env: Vec<EnvPair>The environment variables to set for the executable.
console_output: Option<Utf8UnixPathBuf>The console output path to use for the MicroVm.
Implementations§
Source§impl MicroVmConfig
impl MicroVmConfig
Sourcepub fn builder() -> MicroVmConfigBuilder<(), ()>
pub fn builder() -> MicroVmConfigBuilder<(), ()>
Creates a builder for configuring a new MicroVm configuration.
This is the recommended way to create a new MicroVmConfig instance. The builder pattern provides a more ergonomic interface and ensures all required fields are set.
§Examples
use microsandbox_core::vm::{MicroVmConfig, Rootfs};
use tempfile::TempDir;
let temp_dir = TempDir::new()?;
let config = MicroVmConfig::builder()
.rootfs(Rootfs::Native(temp_dir.path().to_path_buf()))
.memory_mib(1024)
.exec_path("/bin/echo")
.build();Sourcepub fn validate(&self) -> MicrosandboxResult<()>
pub fn validate(&self) -> MicrosandboxResult<()>
Validates the MicroVm configuration.
Performs a series of checks to ensure the configuration is valid:
- Verifies the root path exists and is accessible
- Verifies all host paths in mapped_dirs exist and are accessible
- Ensures number of vCPUs is non-zero
- Ensures memory allocation is non-zero
- Validates executable path and arguments contain only printable ASCII characters
- Validates guest paths don’t overlap or conflict with each other
§Returns
Ok(())if the configuration is validErr(MicrosandboxError::InvalidMicroVMConfig)with details about what failed
§Examples
use microsandbox_core::vm::{MicroVmConfig, Rootfs};
use tempfile::TempDir;
let temp_dir = TempDir::new()?;
let config = MicroVmConfig::builder()
.rootfs(Rootfs::Native(temp_dir.path().to_path_buf()))
.memory_mib(1024)
.exec_path("/bin/echo")
.build();
assert!(config.validate().is_ok());Sourcepub fn validate_command_line(s: &str) -> MicrosandboxResult<()>
pub fn validate_command_line(s: &str) -> MicrosandboxResult<()>
Validates that a command line string contains only allowed characters.
Command line strings (executable paths and arguments) must contain only printable ASCII characters in the range from space (0x20) to tilde (0x7E). This excludes:
- Control characters (newlines, tabs, etc.)
- Non-ASCII Unicode characters
- Null bytes
§Arguments
s- The string to validate
§Returns
Ok(())if the string contains only valid charactersErr(MicrosandboxError::InvalidMicroVMConfig)if invalid characters are found
§Examples
use microsandbox_core::vm::MicroVmConfig;
// Valid strings
assert!(MicroVmConfig::validate_command_line("/bin/echo").is_ok());
assert!(MicroVmConfig::validate_command_line("Hello, World!").is_ok());
// Invalid strings
assert!(MicroVmConfig::validate_command_line("/bin/echo\n").is_err()); // newline
assert!(MicroVmConfig::validate_command_line("hello🌎").is_err()); // emojiTrait Implementations§
Auto Trait Implementations§
impl Freeze for MicroVmConfig
impl RefUnwindSafe for MicroVmConfig
impl Send for MicroVmConfig
impl Sync for MicroVmConfig
impl Unpin for MicroVmConfig
impl UnwindSafe for MicroVmConfig
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more