Skip to main content

WslRunner

Struct WslRunner 

Source
pub struct WslRunner {
    pub distro: Option<String>,
}
Expand description

WSL process runner for Windows.

WslRunner provides secure process execution via WSL using argv-style APIs only. It wraps commands with wsl.exe --exec to execute them in a WSL distribution without shell interpretation.

§Security

WslRunner enforces the following security properties:

  • Uses wsl.exe --exec with argv-style argument passing only
  • Arguments are passed as discrete OsString elements via CommandSpec
  • NO shell string concatenation of user data
  • NO sh -c or shell string evaluation
  • Arguments are validated/normalized at trust boundaries

§Platform Support

WslRunner is only functional on Windows. On non-Windows platforms, it will return an error indicating WSL is not available.

§Example

use xchecker_utils::runner::{WslRunner, ProcessRunner, CommandSpec};
use std::time::Duration;

let runner = WslRunner::new();
let cmd = CommandSpec::new("echo")
    .arg("hello")
    .arg("world");

// On Windows with WSL, this executes: wsl.exe --exec echo hello world
let output = runner.run(&cmd, Duration::from_secs(30)).unwrap();

Fields§

§distro: Option<String>

Optional specific WSL distro to use (e.g., “Ubuntu-22.04”)

Implementations§

Source§

impl WslRunner

Source

pub const fn new() -> Self

Create a new WslRunner using the default WSL distribution.

§Example
use xchecker_utils::runner::WslRunner;

let runner = WslRunner::new();
Source

pub fn with_distro(distro: impl Into<String>) -> Self

Create a new WslRunner targeting a specific WSL distribution.

§Arguments
  • distro - The name of the WSL distribution (e.g., “Ubuntu-22.04”)
§Example
use xchecker_utils::runner::WslRunner;

let runner = WslRunner::with_distro("Ubuntu-22.04");

Trait Implementations§

Source§

impl Clone for WslRunner

Source§

fn clone(&self) -> WslRunner

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 WslRunner

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Default for WslRunner

Source§

fn default() -> WslRunner

Returns the “default value” for a type. Read more
Source§

impl ProcessRunner for WslRunner

Source§

fn run( &self, cmd: &CommandSpec, timeout: Duration, ) -> Result<ProcessOutput, RunnerError>

Execute a command via WSL using argv-style APIs.

This implementation:

  • Wraps the command with wsl.exe --exec (no shell)
  • Uses Command::new().args() only (no shell string evaluation)
  • Validates arguments at trust boundaries
  • Handles timeout via thread-based waiting
  • Captures stdout and stderr
§Arguments
  • cmd - The command specification to execute
  • timeout - Maximum duration to wait for the process to complete
§Returns
  • Ok(ProcessOutput) - The process completed (possibly with non-zero exit code)
  • Err(RunnerError::Timeout) - The process timed out
  • Err(RunnerError::WslExecutionFailed) - Failed to spawn or wait for process
  • Err(RunnerError::WslNotAvailable) - WSL is not available (non-Windows platform)
§Security

This method builds a WSL command using build_wsl_command() which:

  • Uses --exec to bypass shell interpretation
  • Passes arguments as discrete elements via CommandSpec
  • Validates all arguments at trust boundaries
  • NO shell string concatenation of user data occurs

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.