pub struct ProcessSandboxConfig { /* private fields */ }Expand description
Data-oriented sandbox configuration that produces a wrapper program +
args prefix rather than wrapping a std::process::Command directly.
Useful when the consumer needs a different Command type (e.g.
tokio::process::Command) but still wants OS-level sandbox wrapping.
See Self::sandbox_prefix for the produced prefix and
SandboxPolicy for what happens when the OS sandbox is unavailable.
Implementations§
Source§impl ProcessSandboxConfig
impl ProcessSandboxConfig
Sourcepub fn new(writable_root: impl Into<PathBuf>) -> Self
pub fn new(writable_root: impl Into<PathBuf>) -> Self
Create a new sandbox config with the given writable root.
The default sandbox policy is read from the ASTRID_SANDBOX_POLICY
environment variable (required / off). When unset
or unparseable, the policy defaults to SandboxPolicy::Required:
callers will get an error from Self::sandbox_prefix rather than a
silent unsandboxed launch when the OS-level sandbox can’t be applied.
Sourcepub fn with_policy(self, policy: SandboxPolicy) -> Self
pub fn with_policy(self, policy: SandboxPolicy) -> Self
Override the policy for handling unavailable OS-level sandboxing.
See SandboxPolicy for the semantics of each variant.
Sourcepub fn with_network(self, allow: bool) -> Self
pub fn with_network(self, allow: bool) -> Self
Set whether network access is allowed.
Sourcepub fn with_extra_read(self, path: impl Into<PathBuf>) -> Self
pub fn with_extra_read(self, path: impl Into<PathBuf>) -> Self
Add an additional read-only path.
Sourcepub fn with_extra_write(self, path: impl Into<PathBuf>) -> Self
pub fn with_extra_write(self, path: impl Into<PathBuf>) -> Self
Add an additional writable path.
Add a path to hide from the sandboxed process.
On Linux, this overlays an empty tmpfs. On macOS, the path is excluded from the Seatbelt read allowlist.
Sourcepub fn sandbox_prefix(&self) -> Result<Option<SandboxPrefix>>
pub fn sandbox_prefix(&self) -> Result<Option<SandboxPrefix>>
Build the sandbox wrapper prefix for this configuration.
Behaviour depends on the active SandboxPolicy:
SandboxPolicy::Required(default): returnsOk(Some(prefix))when the OS-level sandbox is available, orErrwith an actionable hint when it is not. Callers should propagate the error and refuse to launch the subprocess — this is what preserves the README’s “subprocess capsules are always contained” guarantee.SandboxPolicy::Off: returnsOk(None)unconditionally, without any warning. Use only for trusted dev environments.
§Errors
Returns an error if:
- Any configured path is not valid UTF-8, not absolute, or contains characters that would break sandbox profile syntax (double-quote, backslash, or null byte).
- The active policy is
SandboxPolicy::Requiredand the OS-level sandbox is unavailable. The error message names the most likely cause (kernel.apparmor_restrict_unprivileged_userns=1on Ubuntu 24.04+) and the remediation (sysctlcommand or explicit policy override).
Trait Implementations§
Source§impl Clone for ProcessSandboxConfig
impl Clone for ProcessSandboxConfig
Source§fn clone(&self) -> ProcessSandboxConfig
fn clone(&self) -> ProcessSandboxConfig
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more