Skip to main content

SandboxEnvironment

Struct SandboxEnvironment 

Source
pub struct SandboxEnvironment { /* private fields */ }
Expand description

A handle to a Windows Sandbox environment.

This type can represent either a sandbox that was started through SandboxEnvironmentBuilder::start or an existing sandbox referenced by its SandboxId.

The operations on this type wrap the Windows Sandbox CLI. For command behavior and arguments, see Windows Sandbox command line interface.

Implementations§

Source§

impl SandboxEnvironment

Source

pub fn builder() -> SandboxEnvironmentBuilder

Creates a builder for starting a new sandbox environment.

Source

pub fn list() -> Result<Vec<SandboxEnvironment>, SandboxError>

Lists the currently running sandbox environments for the current user.

§Errors

Returns an error if the wsb list command fails or if its JSON response can’t be deserialized.

Source

pub fn from_id(id: SandboxId) -> Self

Creates a handle for an existing sandbox environment by ID.

This does not start a new sandbox.

§Examples
use wsbx::{SandboxEnvironment, SandboxId};

let id: SandboxId = "12345678-1234-1234-1234-1234567890ab".parse()?;
let environment = SandboxEnvironment::from_id(id);
assert_eq!(environment.id(), id);
Source

pub fn id(&self) -> SandboxId

Returns the sandbox ID associated with this environment.

Source

pub fn exec<C, R>( &self, command: C, run_as: R, ) -> Result<ExecResult, SandboxError>
where C: Into<OsString>, R: Into<RunAs>,

Executes a command in the sandbox.

The command is executed using the specified RunAs context.

§Errors

Returns an error if the wsb exec command fails or if its JSON response can’t be deserialized.

§Examples
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();
Source

pub fn exec_in<C, R, P>( &self, command: C, run_as: R, working_directory: P, ) -> Result<ExecResult, SandboxError>
where C: Into<OsString>, R: Into<RunAs>, P: Into<PathBuf>,

Executes a command in the sandbox with an explicit working directory.

The command is executed using the specified RunAs context and starts in working_directory.

§Errors

Returns an error if the wsb exec command fails or if its JSON response can’t be deserialized.

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

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

pub fn share<P, Q>( &self, host_path: P, sandbox_path: Q, allow_write: bool, ) -> Result<(), SandboxError>
where P: Into<PathBuf>, Q: Into<PathBuf>,

Shares a host folder with the sandbox.

If allow_write is true, the sandbox is allowed to modify the shared folder on the host.

§Errors

Returns an error if the wsb share command fails.

Source

pub fn stop(&self) -> Result<(), SandboxError>

Stops the sandbox environment.

§Errors

Returns an error if the wsb stop command fails.

Source

pub fn connect(&self) -> Result<(), SandboxError>

Opens a remote session to the sandbox environment.

§Errors

Returns an error if the wsb connect command fails.

Source

pub fn ip(&self) -> Result<IpResult, SandboxError>

Returns the network information reported by the sandbox.

§Errors

Returns an error if the wsb ip command fails or if its JSON response can’t be deserialized.

Trait Implementations§

Source§

impl Clone for SandboxEnvironment

Source§

fn clone(&self) -> SandboxEnvironment

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for SandboxEnvironment

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.