pub struct SandboxConfig {
pub allowed_read_paths: Vec<PathBuf>,
pub allowed_write_paths: Vec<PathBuf>,
pub allowed_commands: HashSet<String>,
pub allow_network: bool,
pub allow_env: bool,
pub timeout_ms: u64,
pub max_memory: usize,
pub max_read_size: usize,
pub permissions: HashSet<Permission>,
}Expand description
Configuration for plugin sandboxing.
Fields§
§allowed_read_paths: Vec<PathBuf>Paths the plugin is allowed to read from.
allowed_write_paths: Vec<PathBuf>Paths the plugin is allowed to write to.
allowed_commands: HashSet<String>Commands the plugin is allowed to execute.
allow_network: boolWhether network access is allowed.
allow_env: boolWhether environment access is allowed.
timeout_ms: u64Maximum execution time in milliseconds.
max_memory: usizeMaximum memory in bytes (0 = unlimited).
max_read_size: usizeMaximum file size that can be read.
permissions: HashSet<Permission>Granted permissions.
Implementations§
Source§impl SandboxConfig
impl SandboxConfig
Sourcepub fn permissive() -> Self
pub fn permissive() -> Self
Create a permissive sandbox for trusted plugins.
WARNING: This preset grants broad filesystem read access and environment
variable access. It does NOT grant execute or wildcard command access.
Use only with fully audited, first-party plugins. For untrusted plugins
use SandboxConfig::default or SandboxConfig::minimal instead.
Sourcepub fn allow_read(self, path: impl Into<PathBuf>) -> Self
pub fn allow_read(self, path: impl Into<PathBuf>) -> Self
Add an allowed read path.
Sourcepub fn allow_write(self, path: impl Into<PathBuf>) -> Self
pub fn allow_write(self, path: impl Into<PathBuf>) -> Self
Add an allowed write path.
Sourcepub fn allow_command(self, cmd: impl Into<String>) -> Self
pub fn allow_command(self, cmd: impl Into<String>) -> Self
Allow a specific command.
Sourcepub fn allow_network(self) -> Self
pub fn allow_network(self) -> Self
Enable network access.
Sourcepub fn with_timeout(self, timeout_ms: u64) -> Self
pub fn with_timeout(self, timeout_ms: u64) -> Self
Set timeout.
Sourcepub fn with_memory_limit(self, bytes: usize) -> Self
pub fn with_memory_limit(self, bytes: usize) -> Self
Set memory limit.
Sourcepub fn grant(self, permission: Permission) -> Self
pub fn grant(self, permission: Permission) -> Self
Grant a permission.
Sourcepub fn has_permission(&self, permission: Permission) -> bool
pub fn has_permission(&self, permission: Permission) -> bool
Check if a permission is granted.
Sourcepub fn can_read(&self, path: &Path) -> bool
pub fn can_read(&self, path: &Path) -> bool
Check if reading a path is allowed.
Paths are canonicalized before comparison to prevent traversal attacks
via symlinks or .. components.
Callers must explicitly list allowed paths: an empty allowed_read_paths
list means no paths are allowed (deny-by-default), not unrestricted access.
Sourcepub fn can_write(&self, path: &Path) -> bool
pub fn can_write(&self, path: &Path) -> bool
Check if writing to a path is allowed.
Paths are canonicalized before comparison to prevent traversal attacks
via symlinks or .. components.
Callers must explicitly list allowed paths: an empty allowed_write_paths
list means no paths are allowed (deny-by-default), not unrestricted access.
Sourcepub fn can_execute(&self, command: &str) -> bool
pub fn can_execute(&self, command: &str) -> bool
Check if executing a command is allowed.
Trait Implementations§
Source§impl Clone for SandboxConfig
impl Clone for SandboxConfig
Source§fn clone(&self) -> SandboxConfig
fn clone(&self) -> SandboxConfig
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for SandboxConfig
impl Debug for SandboxConfig
Auto Trait Implementations§
impl Freeze for SandboxConfig
impl RefUnwindSafe for SandboxConfig
impl Send for SandboxConfig
impl Sync for SandboxConfig
impl Unpin for SandboxConfig
impl UnsafeUnpin for SandboxConfig
impl UnwindSafe for SandboxConfig
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> GetSetFdFlags for T
impl<T> GetSetFdFlags for T
Source§fn get_fd_flags(&self) -> Result<FdFlags, Error>where
T: AsFilelike,
fn get_fd_flags(&self) -> Result<FdFlags, Error>where
T: AsFilelike,
self file descriptor.Source§fn new_set_fd_flags(&self, fd_flags: FdFlags) -> Result<SetFdFlags<T>, Error>where
T: AsFilelike,
fn new_set_fd_flags(&self, fd_flags: FdFlags) -> Result<SetFdFlags<T>, Error>where
T: AsFilelike,
Source§fn set_fd_flags(&mut self, set_fd_flags: SetFdFlags<T>) -> Result<(), Error>where
T: AsFilelike,
fn set_fd_flags(&mut self, set_fd_flags: SetFdFlags<T>) -> Result<(), Error>where
T: AsFilelike,
self file descriptor. Read moreSource§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more