pub struct Command { /* private fields */ }Expand description
A sandboxed process builder, providing fine-grained control over how a new process should be spawned.
This mirrors the API of std::process::Command but adds the ability to
apply a sandbox policy that restricts filesystem access.
§Example
use std::path::Path;
use sandbox_run::{Command, Sandbox, ProtectSystem};
let sandbox = Sandbox::new()
.protect_system(ProtectSystem::Strict)
.read_write_paths([Path::new("/tmp")])
.build()
.unwrap();
let output = Command::new("ls")
.arg("/usr")
.sandbox(sandbox)
.output()
.expect("failed to execute process");Implementations§
Source§impl Command
impl Command
Sourcepub fn new<S: AsRef<OsStr>>(program: S) -> Self
pub fn new<S: AsRef<OsStr>>(program: S) -> Self
Constructs a new Command for launching the program at path program.
Sourcepub fn env<K, V>(self, key: K, val: V) -> Self
pub fn env<K, V>(self, key: K, val: V) -> Self
Inserts or updates an environment variable mapping.
Sourcepub fn envs<I, K, V>(self, vars: I) -> Self
pub fn envs<I, K, V>(self, vars: I) -> Self
Adds or updates multiple environment variable mappings.
Sourcepub fn env_remove<K: AsRef<OsStr>>(self, key: K) -> Self
pub fn env_remove<K: AsRef<OsStr>>(self, key: K) -> Self
Removes an environment variable mapping.
Sourcepub fn current_dir<P: AsRef<Path>>(self, dir: P) -> Self
pub fn current_dir<P: AsRef<Path>>(self, dir: P) -> Self
Sets the working directory for the child process.
Sourcepub fn stdin<T: Into<Stdio>>(self, cfg: T) -> Self
pub fn stdin<T: Into<Stdio>>(self, cfg: T) -> Self
Configuration for the child process’s standard input (stdin) handle.
Sourcepub fn stdout<T: Into<Stdio>>(self, cfg: T) -> Self
pub fn stdout<T: Into<Stdio>>(self, cfg: T) -> Self
Configuration for the child process’s standard output (stdout) handle.
Sourcepub fn stderr<T: Into<Stdio>>(self, cfg: T) -> Self
pub fn stderr<T: Into<Stdio>>(self, cfg: T) -> Self
Configuration for the child process’s standard error (stderr) handle.
Sourcepub fn sandbox(self, policy: SandboxPolicy) -> Self
pub fn sandbox(self, policy: SandboxPolicy) -> Self
Apply a sandbox policy to this command.
The sandbox will be applied to the child process after fork but before exec, restricting the process according to the policy.
Sourcepub fn spawn(self) -> Result<Child>
pub fn spawn(self) -> Result<Child>
Executes the command as a child process, returning a handle to it.
Sourcepub fn output(self) -> Result<Output>
pub fn output(self) -> Result<Output>
Executes the command as a child process, waiting for it to finish and collecting all of its output.
Sourcepub fn status(self) -> Result<ExitStatus>
pub fn status(self) -> Result<ExitStatus>
Executes a command as a child process, waiting for it to finish and collecting its status.