Skip to main content

Crate wsbx

Crate wsbx 

Source
Expand description

A type-safe Rust API for controlling Windows Sandbox through the wsb CLI.

This crate is supported on Windows only.

This crate provides:

The configuration model in config follows the Windows Sandbox .wsb configuration format documented by Microsoft. For details, see Use and configure Windows Sandbox.

The runtime API in this crate wraps the Windows Sandbox CLI. For command behavior and arguments, see Windows Sandbox command line interface.

§Examples

Start a sandbox with a typed configuration:

use wsbx::{SandboxConfig, SandboxEnvironment};

let environment = SandboxEnvironment::builder()
    .config(
        SandboxConfig::new()
            .networking(false)
            .memory_in_mb(4096),
    )
    .start()?;

Attach to an existing sandbox by ID and execute a command:

use wsbx::{RunAs, SandboxEnvironment, SandboxId};

let id: SandboxId = "12345678-1234-1234-1234-1234567890ab".parse()?;
let environment = SandboxEnvironment::from_id(id);
let result = environment.exec("cmd.exe", RunAs::System)?;
let _exit_code = result.exit_code();

§Usage

Add this to your Cargo.toml:

[dependencies]
wsbx = "0.1.0"

Re-exports§

pub use crate::config::SandboxConfig;
pub use crate::environment::SandboxEnvironment;
pub use crate::environment::SandboxEnvironmentBuilder;

Modules§

config
Types for constructing Windows Sandbox configuration XML passed to wsb start --config.
environment
Types for interacting with running Windows Sandbox environments through the wsb CLI.

Structs§

SandboxId
The identifier of a Windows Sandbox environment.

Enums§

RunAs
The user context used when executing a command in a sandbox.
SandboxError
Errors that can occur while interacting with Windows Sandbox through wsb.