pub struct SandboxPolicyBuilder { /* private fields */ }sandbox only.Expand description
Builder for constructing SandboxPolicy values incrementally.
Defaults to deny-all: no allowed paths, no network, no process spawning, and no environment variables.
§Example
use adk_sandbox::sandbox::SandboxPolicyBuilder;
let policy = SandboxPolicyBuilder::new()
.allow_read("/usr/lib")
.allow_read_write("/tmp/work")
.allow_network()
.allow_process_spawn()
.env("HOME", "/home/user")
.build();
assert_eq!(policy.allowed_paths.len(), 2);
assert!(policy.allow_network);
assert!(policy.allow_process_spawn);
assert_eq!(policy.env.get("HOME").unwrap(), "/home/user");Implementations§
Source§impl SandboxPolicyBuilder
impl SandboxPolicyBuilder
Sourcepub fn new() -> SandboxPolicyBuilder
pub fn new() -> SandboxPolicyBuilder
Creates a new builder with deny-all defaults.
Sourcepub fn allow_read(self, path: impl Into<PathBuf>) -> SandboxPolicyBuilder
pub fn allow_read(self, path: impl Into<PathBuf>) -> SandboxPolicyBuilder
Adds a read-only allowed path.
Sourcepub fn allow_read_write(self, path: impl Into<PathBuf>) -> SandboxPolicyBuilder
pub fn allow_read_write(self, path: impl Into<PathBuf>) -> SandboxPolicyBuilder
Adds a read-write allowed path.
Sourcepub fn allow_network(self) -> SandboxPolicyBuilder
pub fn allow_network(self) -> SandboxPolicyBuilder
Enables full network access (all domains, all ports).
This overrides any domain-specific rules added via allow_domain.
Sourcepub fn allow_domain(
self,
domain: impl Into<String>,
ports: &[u16],
) -> SandboxPolicyBuilder
pub fn allow_domain( self, domain: impl Into<String>, ports: &[u16], ) -> SandboxPolicyBuilder
Allows network access to a specific domain and ports.
When allow_network is false (the default), only domains added via
this method are accessible. Pass an empty slice for ports to allow
all ports on the domain.
Platform support: Only enforced on macOS (Seatbelt). On Linux and
Windows, domain-level filtering is not available — if any rules are
present but allow_network is false, all network is blocked.
§Example
use adk_sandbox::sandbox::SandboxPolicyBuilder;
let policy = SandboxPolicyBuilder::new()
.allow_domain("api.openai.com", &[443])
.allow_domain("huggingface.co", &[443, 80])
.build();Sourcepub fn allow_process_spawn(self) -> SandboxPolicyBuilder
pub fn allow_process_spawn(self) -> SandboxPolicyBuilder
Enables child process spawning.
Sourcepub fn env(
self,
key: impl Into<String>,
value: impl Into<String>,
) -> SandboxPolicyBuilder
pub fn env( self, key: impl Into<String>, value: impl Into<String>, ) -> SandboxPolicyBuilder
Adds an environment variable key-value pair.
Sourcepub fn build(self) -> SandboxPolicy
pub fn build(self) -> SandboxPolicy
Consumes the builder and returns the constructed SandboxPolicy.