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 --execwith argv-style argument passing only - Arguments are passed as discrete
OsStringelements viaCommandSpec - NO shell string concatenation of user data
- NO
sh -cor 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§
Trait Implementations§
Source§impl ProcessRunner for WslRunner
impl ProcessRunner for WslRunner
Source§fn run(
&self,
cmd: &CommandSpec,
timeout: Duration,
) -> Result<ProcessOutput, RunnerError>
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 executetimeout- 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 outErr(RunnerError::WslExecutionFailed)- Failed to spawn or wait for processErr(RunnerError::WslNotAvailable)- WSL is not available (non-Windows platform)
§Security
This method builds a WSL command using build_wsl_command() which:
- Uses
--execto 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§
impl Freeze for WslRunner
impl RefUnwindSafe for WslRunner
impl Send for WslRunner
impl Sync for WslRunner
impl Unpin for WslRunner
impl UnsafeUnpin for WslRunner
impl UnwindSafe for WslRunner
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more