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
impl SandboxEnvironment
Sourcepub fn builder() -> SandboxEnvironmentBuilder
pub fn builder() -> SandboxEnvironmentBuilder
Creates a builder for starting a new sandbox environment.
Sourcepub fn list() -> Result<Vec<SandboxEnvironment>, SandboxError>
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.
Sourcepub fn from_id(id: SandboxId) -> Self
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);Sourcepub fn exec<C, R>(
&self,
command: C,
run_as: R,
) -> Result<ExecResult, SandboxError>
pub fn exec<C, R>( &self, command: C, run_as: R, ) -> Result<ExecResult, SandboxError>
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();Sourcepub fn exec_in<C, R, P>(
&self,
command: C,
run_as: R,
working_directory: P,
) -> Result<ExecResult, SandboxError>
pub fn exec_in<C, R, P>( &self, command: C, run_as: R, working_directory: P, ) -> Result<ExecResult, SandboxError>
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();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.
Sourcepub fn stop(&self) -> Result<(), SandboxError>
pub fn stop(&self) -> Result<(), SandboxError>
Trait Implementations§
Source§impl Clone for SandboxEnvironment
impl Clone for SandboxEnvironment
Source§fn clone(&self) -> SandboxEnvironment
fn clone(&self) -> SandboxEnvironment
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more