### Basic VM Configuration and Start Source: https://github.com/arcbox-labs/arcbox/blob/master/virt/arcbox-vz/README.md Demonstrates how to configure a basic Linux virtual machine, set its CPU and memory, specify a boot loader, and then build and start the VM. ```APIDOC ## Basic VM Configuration and Start ### Description This example shows the fundamental steps to configure and launch a virtual machine using arcbox-vz. It includes checking for virtualization support, setting CPU and memory, configuring a Linux boot loader, and initiating the VM. ### Method N/A (Illustrative code) ### Endpoint N/A (Local operation) ### Parameters N/A ### Request Example ```rust use arcbox_vz::{ VirtualMachineConfiguration, LinuxBootLoader, VZError, }; #[tokio::main] async fn main() -> Result<(), VZError> { // Check if virtualization is supported if !arcbox_vz::is_supported() { return Err(VZError::NotSupported); } // Configure VM let mut config = VirtualMachineConfiguration::new()?; config .set_cpu_count(2) .set_memory_size(512 * 1024 * 1024); // Set boot loader let boot_loader = LinuxBootLoader::new("/path/to/kernel")?; config.set_boot_loader(boot_loader); // Build and start VM let vm = config.build()?; vm.start().await?; // Graceful shutdown vm.request_stop()?; Ok(()) } ``` ### Response #### Success Response (200) N/A (Illustrative code) #### Response Example N/A ``` -------------------------------- ### Verify Code Signing Setup Source: https://github.com/arcbox-labs/arcbox/blob/master/CONTRIBUTING.md Commands to verify that the required Developer ID certificate is installed and that the binary has the correct entitlements embedded. ```bash security find-identity -v -p codesigning | grep "ArcBox" codesign -d --entitlements - target/debug/arcbox-daemon ``` -------------------------------- ### Run Embedded gRPC Server Example - Bash Source: https://github.com/arcbox-labs/arcbox/blob/master/virt/arcbox-vm/README.md Command to run the serve example, showcasing how to integrate SandboxServiceImpl and SandboxSnapshotServiceImpl into a Tonic server listening on a Unix socket. This is a reference for embedding sandbox services into a daemon. ```Bash # from arcbox workspace root cargo run -p arcbox-vm --example serve -- --unix-socket /tmp/vmm-test.sock ``` -------------------------------- ### Run arcbox-vm Examples Source: https://github.com/arcbox-labs/arcbox/blob/master/virt/arcbox-vm/README.md Executes example binaries within the arcbox-vm component. These examples may require the Firecracker binary and CAP_NET_ADMIN privileges. ```bash cargo run -p arcbox-vm --example sandbox_lifecycle cargo run -p arcbox-vm --example serve ``` -------------------------------- ### Run Sandbox Lifecycle Example - Bash Source: https://github.com/arcbox-labs/arcbox/blob/master/virt/arcbox-vm/README.md Command to execute the sandbox_lifecycle example, which demonstrates the full SandboxManager API in Rust. This includes creating, polling, inspecting, listing, checkpointing, removing, and restoring sandboxes. ```Bash # from arcbox workspace root cargo run -p arcbox-vm --example sandbox_lifecycle ``` -------------------------------- ### Initialize and Start a Virtual Machine Source: https://github.com/arcbox-labs/arcbox/blob/master/virt/arcbox-vz/README.md Demonstrates how to check for virtualization support, configure a VM with CPU and memory settings, define a Linux boot loader, and manage the VM lifecycle using async/await. ```rust use arcbox_vz::{ VirtualMachineConfiguration, LinuxBootLoader, GenericPlatform, SocketDeviceConfiguration, VZError, }; #[tokio::main] async fn main() -> Result<(), VZError> { if !arcbox_vz::is_supported() { return Err(VZError::NotSupported); } let mut config = VirtualMachineConfiguration::new()?; config .set_cpu_count(2) .set_memory_size(512 * 1024 * 1024); let boot_loader = LinuxBootLoader::new("/path/to/kernel")?; config.set_boot_loader(boot_loader); let vm = config.build()?; vm.start().await?; vm.request_stop()?; Ok(()) } ``` -------------------------------- ### Initialize and Start ArcBox Runtime Source: https://github.com/arcbox-labs/arcbox/blob/master/app/arcbox-core/README.md Demonstrates how to instantiate the ArcBox Runtime using default configuration, initialize the environment, and ensure the default virtual machine is operational. ```rust use arcbox_core::{Config, Runtime}; let runtime = Runtime::new(Config::default())?; runtime.init().await?; let cid = runtime.ensure_vm_ready().await?; println!("default machine CID: {cid}"); ``` -------------------------------- ### Install ArcBox Helper Service Source: https://github.com/arcbox-labs/arcbox/blob/master/CONTRIBUTING.md Builds the CLI and helper components in release mode and registers the helper as a system-wide launchd daemon. ```bash cargo build --release -p arcbox-cli -p arcbox-helper sudo ./target/release/abctl _install ``` -------------------------------- ### Rust Client for Kubernetes Service Source: https://context7.com/arcbox-labs/arcbox/llms.txt Example Rust client for the KubernetesService gRPC API. It demonstrates starting a Kubernetes cluster, retrieving its kubeconfig, and checking its status. ```rust // Rust client example use arcbox_grpc::v1::kubernetes_service_client::KubernetesServiceClient; use arcbox_protocol::v1::{KubernetesStartRequest, KubernetesStatusRequest}; async fn manage_kubernetes(channel: tonic::transport::Channel) -> Result<(), Box> { let mut client = KubernetesServiceClient::new(channel); // Start Kubernetes cluster let response = client.start(tonic::Request::new( KubernetesStartRequest {} )).await?.into_inner(); println!("Kubernetes {}", if response.api_ready { "ready" } else { "starting" }); println!("Endpoint: {}", response.endpoint); // Get kubeconfig let kubeconfig = client.get_kubeconfig(tonic::Request::new( arcbox_protocol::v1::KubernetesKubeconfigRequest {} )).await?.into_inner(); std::fs::write("arcbox-kubeconfig.yaml", kubeconfig.kubeconfig)?; // Check status let status = client.status(tonic::Request::new( KubernetesStatusRequest {} )).await?.into_inner(); println!("Running: {}, API Ready: {}", status.running, status.api_ready); Ok(()) } ``` -------------------------------- ### Implement Machine Lifecycle Management in Rust Source: https://context7.com/arcbox-labs/arcbox/llms.txt Demonstrates using the tonic gRPC client to create, start, and list virtual machines. It requires the arcbox_grpc and tonic crates for network communication. ```rust use arcbox_grpc::v1::machine_service_client::MachineServiceClient; use arcbox_protocol::v1::{CreateMachineRequest, StartMachineRequest}; use tonic::transport::Channel; async fn create_and_start_machine(channel: Channel) -> Result<(), Box> { let mut client = MachineServiceClient::new(channel); client.create(tonic::Request::new(CreateMachineRequest { name: "dev".to_string(), cpus: 4, memory: 8 * 1024 * 1024 * 1024, disk_size: 100 * 1024 * 1024 * 1024, distro: "ubuntu".to_string(), version: "22.04".to_string(), ..Default::default() })).await?; client.start(tonic::Request::new(StartMachineRequest { id: "dev".to_string(), })).await?; let response = client.list(tonic::Request::new( arcbox_protocol::v1::ListMachinesRequest { all: true } )).await?; for machine in response.into_inner().machines { println!("{}: {} ({})", machine.name, machine.state, machine.ip_address); } Ok(()) } ``` -------------------------------- ### Run ArcBox Helper and Daemon in Development Source: https://github.com/arcbox-labs/arcbox/blob/master/CONTRIBUTING.md Starts the helper and daemon processes manually for local development, allowing them to communicate via a Unix socket. ```bash # Terminal 1: run the helper (builds + sudo) make run-helper # Terminal 2: run the daemon (auto-connects to /tmp/arcbox-helper.sock) make run-daemon ``` -------------------------------- ### Create and Configure VM in Rust using Arcbox Hypervisor Source: https://github.com/arcbox-labs/arcbox/blob/master/virt/arcbox-hypervisor/README.md This Rust code snippet demonstrates how to create a platform-appropriate hypervisor, configure a new virtual machine with specified CPU and memory, and then create and start the VM. It utilizes the `create_hypervisor` function and the `VmConfig` builder pattern. ```Rust use arcbox_hypervisor::{create_hypervisor, VmConfig}; // Create platform-appropriate hypervisor let hypervisor = create_hypervisor()?; // Configure VM let config = VmConfig::builder() .vcpu_count(4) .memory_size(4 * 1024 * 1024 * 1024) // 4GB .build(); // Create and start VM let vm = hypervisor.create_vm(config)?; ``` -------------------------------- ### Run ArcBox Daemon Source: https://github.com/arcbox-labs/arcbox/blob/master/CONTRIBUTING.md Starts the ArcBox daemon process to verify startup logs and service availability. ```bash make run-daemon ``` -------------------------------- ### Reload and Reinstall Helper Source: https://github.com/arcbox-labs/arcbox/blob/master/CONTRIBUTING.md Commands to update the helper service after code changes or perform a fresh installation. ```bash # Reload helper after code changes make reload-helper # Fresh launchd install make install-helper ``` -------------------------------- ### Rust Client for Sandbox Service Source: https://context7.com/arcbox-labs/arcbox/llms.txt Example Rust client demonstrating how to interact with the SandboxService gRPC API. It covers creating a sandbox with resource limits and executing a command using bidirectional streaming for interactive sessions. ```rust // Rust client example with bidirectional exec use arcbox_grpc::SandboxServiceClient; use arcbox_protocol::sandbox_v1::{ CreateSandboxRequest, ExecInput, ExecRequest, ResourceLimits, exec_input::Payload, }; use tokio_stream::wrappers::ReceiverStream; use tonic::metadata::MetadataValue; async fn run_command_in_sandbox(channel: tonic::transport::Channel) -> Result<(), Box> { let mut client = SandboxServiceClient::new(channel); // Create sandbox with resource limits let mut request = tonic::Request::new(CreateSandboxRequest { id: "my-sandbox".to_string(), limits: Some(ResourceLimits { vcpus: 2, memory_mib: 512, }), ttl_seconds: 3600, ..Default::default() }); // Route to default machine request.metadata_mut().insert("x-machine", MetadataValue::from_static("default")); let resp = client.create(request).await?.into_inner(); println!("Created sandbox {} with IP {}", resp.id, resp.ip_address); // Execute interactive command with bidirectional streaming let (tx, rx) = tokio::sync::mpsc::channel::(16); // Send init message tx.send(ExecInput { payload: Some(Payload::Init(ExecRequest { id: "my-sandbox".to_string(), cmd: vec!["/bin/bash".to_string()], tty: true, ..Default::default() })), }).await?; // Send stdin in background tokio::spawn(async move { tx.send(ExecInput { payload: Some(Payload::Stdin(b"echo hello\n".to_vec())), }).await.ok(); }); let mut request = tonic::Request::new(ReceiverStream::new(rx)); request.metadata_mut().insert("x-machine", MetadataValue::from_static("default")); let mut stream = client.exec(request).await?.into_inner(); while let Some(output) = stream.message().await? { print!("{}", String::from_utf8_lossy(&output.data)); if output.done { println!("Exit code: {}", output.exit_code); break; } } Ok(()) } ``` -------------------------------- ### Manage Kubernetes Cluster Integration Source: https://context7.com/arcbox-labs/arcbox/llms.txt Commands to start, stop, and integrate a native k3s cluster. Includes utilities for kubeconfig management and host-level kubectl integration. ```bash arcbox kubernetes start arcbox kubernetes enable arcbox kubernetes status arcbox kubernetes kubeconfig > ~/.kube/arcbox.yaml arcbox kubernetes restart arcbox kubernetes stop arcbox kubernetes delete arcbox kubernetes disable ``` -------------------------------- ### GET /version Source: https://github.com/arcbox-labs/arcbox/blob/master/app/arcbox-docker/README.md Retrieves version information from the guest dockerd instance to ensure compatibility with Docker CLI tools. ```APIDOC ## GET /version ### Description Returns version information about the Docker engine and the host environment. ### Method GET ### Endpoint /version ### Response #### Success Response (200) - **Version** (string) - The Docker API version. - **ApiVersion** (string) - The negotiated API version. - **MinAPIVersion** (string) - The minimum supported API version. #### Response Example { "Version": "24.0.5", "ApiVersion": "1.43", "MinAPIVersion": "1.12" } ``` -------------------------------- ### Manage ArcBox Machines (Full VMs) Source: https://context7.com/arcbox-labs/arcbox/llms.txt Commands for managing full Linux virtual machines. This includes creating machines with specified resources (CPUs, memory, disk), mounting directories, starting, listing, inspecting, SSHing, executing commands, pinging, retrieving system info, and removing machines. ```bash # Create a new machine with custom resources arcbox machine create dev --cpus 4 --memory 8192 --disk 100 # Create machine with directory mounts arcbox machine create workspace --mount /Users/me/projects:/workspace # Start a machine arcbox machine start dev # List all machines arcbox machine ls # Get machine status arcbox machine status dev # Inspect machine (JSON output) arcbox machine inspect dev # SSH into a machine arcbox machine ssh dev # Execute command in machine arcbox machine exec dev -- ls -la / # Ping machine agent arcbox machine ping dev # Get guest system info arcbox machine info dev # Stop and remove machine arcbox machine stop dev arcbox machine rm dev --force --volumes ``` -------------------------------- ### Manage ArcBox Virtual Machines Source: https://github.com/arcbox-labs/arcbox/blob/master/app/arcbox-cli/README.md Commands to create, start, list, and stop Linux virtual machines within the ArcBox environment. These operations interact with the ArcBox daemon to manage VM lifecycles. ```bash abctl machine create myvm abctl machine start myvm abctl machine list abctl machine stop myvm ``` -------------------------------- ### Configure and Build a VM with VmBuilder Source: https://github.com/arcbox-labs/arcbox/blob/master/virt/arcbox-vmm/README.md Demonstrates how to use the fluent VmBuilder API to configure and construct a new virtual machine. This includes setting the VM name, number of CPUs, memory size, kernel path, kernel command line, and attaching block and network devices. The builder returns a Result, and the built VM can then be run. ```rust use arcbox_vmm::builder::VmBuilder; let vm = VmBuilder::new() .name("my-vm") .cpus(4) .memory_gb(2) .kernel("/path/to/vmlinux") .cmdline("console=hvc0 root=/dev/vda") .block_device("/path/to/disk.img", false) .network_device(None, None) .build()?; vm.run().await?; ``` -------------------------------- ### Initialize and Interact with ArcBox Runtime Source: https://context7.com/arcbox-labs/arcbox/llms.txt Demonstrates how to configure and initialize the ArcBox Runtime, manage VM lifecycles, communicate with guest agents via RPC, and configure networking features like DNS and port forwarding. ```rust use arcbox_core::{Config, Runtime}; use std::sync::Arc; async fn initialize_runtime() -> Result, Box> { let config = Config { data_dir: dirs::home_dir().unwrap().join(".arcbox"), socket_path: None, grpc_socket_path: None, kernel_path: None, ..Default::default() }; let runtime = Runtime::new(config)?; runtime.init().await?; let cid = runtime.ensure_vm_ready().await?; println!("Default machine CID: {}", cid); Ok(Arc::new(runtime)) } async fn use_runtime(runtime: &Runtime) -> Result<(), Box> { let machines = runtime.machine_manager().list(); for m in machines { println!("Machine: {} ({})", m.name, m.state); } let mut agent = runtime.get_agent("default")?; let pong = agent.ping().await?; println!("Agent version: {}", pong.version); runtime.register_dns("my-container", "web", "172.17.0.2".parse()?).await; runtime.start_port_forwarding_for( "default", "container-abc123", &[("0.0.0.0".to_string(), 8080, 80, "tcp".to_string())] ).await?; Ok(()) } ``` -------------------------------- ### GET /containers/json Source: https://github.com/arcbox-labs/arcbox/blob/master/app/arcbox-docker/README.md Lists containers managed by the ArcBox environment. ```APIDOC ## GET /containers/json ### Description Returns a list of containers currently managed by the ArcBox-docker proxy. ### Method GET ### Endpoint /containers/json ### Query Parameters - **all** (boolean) - Optional - If true, return all containers, including stopped ones. ### Response #### Success Response (200) - **Id** (string) - The container ID. - **Names** (array) - List of container names. - **State** (string) - Current state of the container. #### Response Example [ { "Id": "a1b2c3d4e5f6", "Names": ["/my-container"], "State": "running" } ] ``` -------------------------------- ### GET /containers/json Source: https://context7.com/arcbox-labs/arcbox/llms.txt Retrieve a list of all containers currently managed by the system. ```APIDOC ## GET /containers/json ### Description Returns a list of containers. ### Method GET ### Endpoint /containers/json ### Response #### Success Response (200) - **containers** (array) - List of container objects #### Response Example [ { "id": "c123", "name": "web-server", "state": "running" } ] ``` -------------------------------- ### Create Container with Configuration (Rust) Source: https://github.com/arcbox-labs/arcbox/blob/master/runtime/arcbox-container/README.md Demonstrates how to create a container using `ContainerConfig` in Rust. It initializes a container with a specified image and command, then asserts its initial state. Dependencies include the `arcbox_container` crate. ```Rust use arcbox_container::{Container, ContainerConfig, ContainerState}; let config = ContainerConfig { image: "alpine:latest".to_string(), cmd: vec!["sh".to_string()], ..Default::default() }; let container = Container::with_config("demo", config); assert_eq!(container.state, ContainerState::Created); ``` -------------------------------- ### POST /containers/create Source: https://context7.com/arcbox-labs/arcbox/llms.txt Create a new container instance with specified configuration. ```APIDOC ## POST /containers/create ### Description Creates a new container. ### Method POST ### Endpoint /containers/create ### Request Body - **image** (string) - Required - Image name to use - **name** (string) - Optional - Container name ### Request Example { "image": "ubuntu:latest", "name": "my-container" } ### Response #### Success Response (200) - **id** (string) - The ID of the created container ``` -------------------------------- ### MachineService gRPC API Source: https://context7.com/arcbox-labs/arcbox/llms.txt The MachineService provides gRPC methods to manage virtual machine lifecycles including creation, starting, stopping, and inspection. ```APIDOC ## gRPC MachineService ### Description Provides programmatic control over VM lifecycle. ### Methods - **Create**(CreateMachineRequest) returns (CreateMachineResponse) - **Start**(StartMachineRequest) returns (Empty) - **Stop**(StopMachineRequest) returns (Empty) - **List**(ListMachinesRequest) returns (ListMachinesResponse) ### Request Example (Rust) ```rust client.create(tonic::Request::new(CreateMachineRequest { name: "dev".to_string(), cpus: 4, memory: 8589934592, distro: "ubuntu".to_string(), version: "22.04".to_string(), ..Default::default() })).await?; ``` ``` -------------------------------- ### Bundle Management with Builder Pattern Source: https://github.com/arcbox-labs/arcbox/blob/master/runtime/arcbox-oci/README.md Demonstrates how to load an existing OCI bundle and create a new one using the BundleBuilder. This includes setting container properties like hostname, arguments, environment variables, and current working directory. ```APIDOC ## Bundle Management with Builder Pattern ### Description This section illustrates how to interact with OCI bundles. You can load an existing bundle from a specified path or construct a new bundle using a builder pattern, allowing for customization of various container settings. ### Method N/A (Code examples) ### Endpoint N/A (Code examples) ### Parameters N/A (Code examples) ### Request Example N/A (Code examples) ### Response N/A (Code examples) ## Loading an Existing Bundle ### Description Loads an OCI bundle from a given file path. ### Method N/A (Code examples) ### Endpoint N/A (Code examples) ### Code Example ```rust use arcbox_oci::Bundle; // Load an existing bundle let bundle = Bundle::load("/path/to/bundle")?; println!("OCI version: {}", bundle.spec().oci_version); ``` ## Creating a New Bundle with Builder ### Description Creates a new OCI bundle using a builder pattern. This allows for programmatic configuration of the bundle's properties before building it to a specified directory. ### Method N/A (Code examples) ### Endpoint N/A (Code examples) ### Code Example ```rust use arcbox_oci::{BundleBuilder, Spec}; // Create a new bundle with builder let bundle = BundleBuilder::new() .hostname("my-container") .args(vec!["nginx".to_string(), "-g".to_string(), "daemon off;".to_string()]) .add_env("NGINX_HOST", "localhost") .cwd("/") .build("/path/to/new-bundle")?; ``` ``` -------------------------------- ### Initialize NetworkManager with Rust Source: https://github.com/arcbox-labs/arcbox/blob/master/virt/arcbox-net/README.md Demonstrates how to configure and initialize the NetworkManager using the NetConfig struct. It sets up the network mode and allocates an IP address for a virtual machine. ```rust use arcbox_net::{NetworkManager, NetConfig, NetworkMode}; let config = NetConfig { mode: NetworkMode::Nat, mac: None, mtu: 1500, bridge: None, multiqueue: false, num_queues: 1, }; let manager = NetworkManager::new(config); manager.start()?; let ip = manager.allocate_ip(); ``` -------------------------------- ### Kubernetes Service gRPC API Definition Source: https://context7.com/arcbox-labs/arcbox/llms.txt Defines the KubernetesService for managing k3s cluster lifecycle, including starting, stopping, deleting, checking status, and retrieving kubeconfig. ```protobuf // Kubernetes service definition (arcbox_protocol::v1) service KubernetesService { rpc Start(KubernetesStartRequest) returns (KubernetesStartResponse); rpc Stop(KubernetesStopRequest) returns (KubernetesStopResponse); rpc Delete(KubernetesDeleteRequest) returns (KubernetesDeleteResponse); rpc Status(KubernetesStatusRequest) returns (KubernetesStatusResponse); rpc GetKubeconfig(KubernetesKubeconfigRequest) returns (KubernetesKubeconfigResponse); } ``` -------------------------------- ### Initialize Machine Service in Rust Source: https://github.com/arcbox-labs/arcbox/blob/master/app/arcbox-api/README.md Demonstrates how to initialize the MachineServiceImpl in Rust. This involves creating a Runtime instance and then instantiating the service with the runtime. It's a common pattern for setting up the API layer. ```rust use arcbox_api::MachineServiceImpl; use arcbox_core::Runtime; use std::sync::Arc; let runtime = Arc::new(Runtime::new(Default::default())?); let _machine_service = MachineServiceImpl::new(runtime); ``` -------------------------------- ### Configure VirtioFS Directory Sharing Source: https://github.com/arcbox-labs/arcbox/blob/master/virt/arcbox-vz/README.md Shows how to set up a Virtio file system device for directory sharing between the host and the guest VM using the SharedDirectory and SingleDirectoryShare types. ```rust use arcbox_vz::{SharedDirectory, SingleDirectoryShare, VirtioFileSystemDeviceConfiguration}; let share = SharedDirectory::new("/host/path", false)?; let dir_share = SingleDirectoryShare::new(share); let fs_device = VirtioFileSystemDeviceConfiguration::new("myshare", dir_share); config.set_directory_sharing_devices(vec![fs_device]); ``` -------------------------------- ### Manage ArcBox Daemon Lifecycle Source: https://context7.com/arcbox-labs/arcbox/llms.txt Commands to control the ArcBox daemon process, including starting in foreground/background, stopping, and checking its status. Options include custom socket paths and Docker CLI integration. ```bash arcbox daemon start arcbox daemon start -f arcbox daemon start --socket /tmp/docker.sock --grpc-socket /tmp/grpc.sock arcbox daemon start --docker-integration arcbox daemon stop arcbox daemon status ``` -------------------------------- ### Manual Build and Sign Source: https://github.com/arcbox-labs/arcbox/blob/master/CONTRIBUTING.md Builds the CLI and daemon components using cargo and manually applies code signing with required entitlements. ```bash cargo build -p arcbox-cli -p arcbox-daemon codesign --force --options runtime --entitlements bundle/arcbox.entitlements -s "Developer ID Application: ArcBox, Inc. (422ACSY6Y5)" target/debug/arcbox-daemon ./target/debug/arcbox-daemon ``` -------------------------------- ### Runtime Initialization and VM Readiness Source: https://github.com/arcbox-labs/arcbox/blob/master/app/arcbox-core/README.md This section describes the primary orchestration flow for initializing the ArcBox runtime and ensuring the default virtual machine is operational. ```APIDOC ## POST /runtime/init ### Description Initializes the ArcBox runtime environment, preparing necessary state and assets for machine orchestration. ### Method POST ### Endpoint /runtime/init ### Parameters #### Request Body - **config** (Object) - Required - Configuration object containing runtime settings such as network parameters and machine defaults. ### Request Example { "config": { "default_machine": "vm-01", "network_mode": "bridge" } } ### Response #### Success Response (200) - **status** (string) - Indicates successful initialization of the runtime. #### Response Example { "status": "initialized" } ## GET /runtime/vm/ready ### Description Ensures the default virtual machine is running and returns the context identifier (CID) for guest-agent communication. ### Method GET ### Endpoint /runtime/vm/ready ### Response #### Success Response (200) - **cid** (integer) - The CID assigned to the default machine for vsock communication. #### Response Example { "cid": 3 } ``` -------------------------------- ### Cross-compile vm-agent to Linux (Static) Source: https://github.com/arcbox-labs/arcbox/blob/master/virt/arcbox-vm/README.md Cross-compiles the vm-agent for x86_64 Linux using a musl toolchain. This is necessary because vm-agent targets Linux and requires static linking. It involves installing the target architecture and then building the agent. ```bash rustup target add x86_64-unknown-linux-musl brew install FiloSottile/musl-cross/musl-cross # macOS cargo build -p arcbox-vm --bin vmm-guest-agent --target x86_64-unknown-linux-musl --release ``` -------------------------------- ### Initialize Arcbox Filesystem in Rust Source: https://github.com/arcbox-labs/arcbox/blob/master/virt/arcbox-fs/README.md Demonstrates how to initialize the arcbox-fs with custom configuration. This involves setting up FsConfig with sharing details and creating a PassthroughFs instance, which is then used to initialize a FuseDispatcher. ```rust use arcbox_fs::{FsConfig, FuseDispatcher, PassthroughConfig, PassthroughFs}; let config = FsConfig { tag: "arcbox".to_string(), source: "/path/to/share".to_string(), num_threads: 4, writeback_cache: true, cache_timeout: 1, }; let fs = PassthroughFs::new(PassthroughConfig::default())?; let dispatcher = FuseDispatcher::new(fs); ``` -------------------------------- ### Manage ArcBox Sandboxes (MicroVMs) Source: https://context7.com/arcbox-labs/arcbox/llms.txt Commands for managing lightweight microVM sandboxes, optimized for fast boot times (<200ms) and isolation. Operations include creating, listing, inspecting, running commands (streaming or interactive), subscribing to lifecycle events, checkpointing, and restoring from snapshots. ```bash # Create a new sandbox arcbox sandbox create --cpus 2 --memory 512 --label env=test # Create sandbox with custom ID and TTL arcbox sandbox create --id my-sandbox --ttl 3600 # List sandboxes arcbox sandbox ls # List sandboxes by state arcbox sandbox ls --state running # Inspect sandbox details (JSON) arcbox sandbox inspect abc123-def456 # Run command in sandbox (streaming output) arcbox sandbox run abc123-def456 -- python script.py arcbox sandbox run abc123-def456 --tty -- /bin/sh # Execute interactive command (bidirectional I/O) arcbox sandbox exec abc123-def456 -t -- /bin/bash # Subscribe to sandbox lifecycle events arcbox sandbox events # Checkpoint sandbox to snapshot arcbox sandbox checkpoint abc123-def456 --name "before-tests" # Restore sandbox from snapshot (<50ms) arcbox sandbox restore snap-789 --sandbox-id restored-sandbox ``` -------------------------------- ### Manage OCI Bundles and Specifications Source: https://github.com/arcbox-labs/arcbox/blob/master/runtime/arcbox-oci/README.md Demonstrates loading existing OCI bundles, creating new bundles using the builder pattern, and validating configuration files. This requires the arcbox_oci crate and filesystem access to the bundle path. ```rust use arcbox_oci::{Bundle, BundleBuilder, Spec}; // Load an existing bundle let bundle = Bundle::load("/path/to/bundle")?; println!("OCI version: {}", bundle.spec().oci_version); // Create a new bundle with builder let bundle = BundleBuilder::new() .hostname("my-container") .args(vec!["nginx".to_string(), "-g".to_string(), "daemon off;".to_string()]) .add_env("NGINX_HOST", "localhost") .cwd("/") .build("/path/to/new-bundle")?; // Parse config directly let spec = Spec::load("/path/to/config.json")?; spec.validate()?; ``` -------------------------------- ### Create Sandbox using Direct API - Rust Source: https://github.com/arcbox-labs/arcbox/blob/master/virt/arcbox-vm/README.md Demonstrates how to create a new sandbox using the direct API of the arcbox-vm library. It initializes a SandboxManager and then calls create_sandbox with specified resources like vCPUs and memory. Dependencies include std::sync::Arc and arcbox_vm components. ```Rust use std::sync::Arc; use arcbox_vm::{SandboxManager, SandboxSpec, VmmConfig}; let manager = Arc::new(SandboxManager::new(VmmConfig::default())?); let (id, ip) = manager.create_sandbox(SandboxSpec { vcpus: 1, memory_mib: 512, ..Default::default() }).await?; ``` -------------------------------- ### Cross-Compile Guest Agent Source: https://github.com/arcbox-labs/arcbox/blob/master/CONTRIBUTING.md Sets up the musl-cross toolchain and builds the arcbox-agent for the Linux guest VM. The resulting binary must be placed in the daemon's data directory. ```bash brew install FiloSottile/musl-cross/musl-cross rustup target add aarch64-unknown-linux-musl make build-agent mkdir -p ~/.arcbox/bin cp target/aarch64-unknown-linux-musl/release/arcbox-agent ~/.arcbox/bin/ ``` -------------------------------- ### VirtioFS Directory Sharing Source: https://github.com/arcbox-labs/arcbox/blob/master/virt/arcbox-vz/README.md Illustrates how to configure a VirtioFS shared directory, allowing the host and guest to share files. ```APIDOC ## VirtioFS Directory Sharing ### Description This example demonstrates how to set up a VirtioFS shared directory, enabling file system access between the host machine and the virtual machine. It configures a specific host directory to be accessible within the guest. ### Method N/A (Illustrative code) ### Endpoint N/A (Configuration within VM setup) ### Parameters N/A ### Request Example ```rust use arcbox_vz::{ SharedDirectory, SingleDirectoryShare, VirtioFileSystemDeviceConfiguration, VirtualMachineConfiguration, }; // Assume 'config' is an existing VirtualMachineConfiguration instance // let mut config = VirtualMachineConfiguration::new()?; // VirtioFS directory share let share = SharedDirectory::new("/host/path", false)?; let dir_share = SingleDirectoryShare::new(share); let fs_device = VirtioFileSystemDeviceConfiguration::new("myshare", dir_share); // config.set_directory_sharing_devices(vec![fs_device]); // This line would be part of the main config setup ``` ### Response #### Success Response (200) N/A (Illustrative code) #### Response Example N/A ``` -------------------------------- ### Create Machine Service Client Request (Rust) Source: https://github.com/arcbox-labs/arcbox/blob/master/rpc/arcbox-grpc/README.md Demonstrates how to create a `ListMachinesRequest` for the `MachineServiceClient` using the `arcbox-grpc` and `arcbox-protocol` crates. This is a common pattern for interacting with ArcBox services via gRPC. ```Rust use arcbox_grpc::MachineServiceClient; use arcbox_protocol::v1::ListMachinesRequest; let request = tonic::Request::new(ListMachinesRequest { all: true }); // client.list(request).await?; # let _ = request; ```