use super::SandboxExecutor;
use anyhow::{Context, Result};
use std::path::Path;
use std::process::{Command, Output};
pub struct WindowsSandbox;
impl SandboxExecutor for WindowsSandbox {
fn name(&self) -> &'static str {
"windows-job-objects"
}
fn execute(
&self,
command: &str,
args: &[&str],
work_dir: &Path,
allow_network: bool,
) -> Result<Output> {
let mut cmd = Command::new(command);
cmd.args(args).current_dir(work_dir);
if !allow_network {
cmd.env("RIVOX_SANDBOX_NETWORK", "0");
cmd.env_remove("HTTP_PROXY");
cmd.env_remove("HTTPS_PROXY");
cmd.env_remove("http_proxy");
cmd.env_remove("https_proxy");
}
cmd.env("RIVOX_SANDBOX_ACTIVE", "1");
cmd.env("RIVOX_SANDBOX_ENGINE", "windows-job-objects");
let output = cmd.output().with_context(|| {
format!(
"Windows sandbox failed executing {} in {}",
command,
work_dir.display()
)
})?;
Ok(output)
}
}