pub struct AgentCapabilities {
pub read: bool,
pub write: bool,
pub exec: bool,
pub allowed_paths: Vec<String>,
pub denied_paths: Vec<String>,
pub allowed_commands: Vec<String>,
pub denied_commands: Vec<String>,
}Expand description
Capabilities that control what the agent can do.
This provides a security model for primitive tools (Read, Write, Grep, Glob, Bash). Paths are matched using glob patterns, commands using regex patterns.
By default, everything is allowed — the SDK is unopinionated and leaves security policy to the client. Use the builder methods to configure restrictions.
§Example
use agent_sdk::AgentCapabilities;
// Read-only agent that can only access src/ directory
let caps = AgentCapabilities::read_only()
.with_allowed_paths(vec!["src/**/*".into()]);
// Full access agent with some restrictions
let caps = AgentCapabilities::full_access()
.with_denied_paths(vec!["**/.env*".into(), "**/secrets/**".into()]);Fields§
§read: boolCan read files
write: boolCan write/edit files
exec: boolCan execute shell commands
allowed_paths: Vec<String>Allowed path patterns (glob). Empty means all paths allowed.
denied_paths: Vec<String>Denied path patterns (glob). Takes precedence over allowed_paths.
allowed_commands: Vec<String>Allowed commands (regex patterns). Empty means all commands allowed when exec=true.
denied_commands: Vec<String>Denied commands (regex patterns). Takes precedence over allowed_commands.
Implementations§
Source§impl AgentCapabilities
impl AgentCapabilities
Sourcepub const fn full_access() -> Self
pub const fn full_access() -> Self
Create full access capabilities
Sourcepub const fn with_write(self, enabled: bool) -> Self
pub const fn with_write(self, enabled: bool) -> Self
Builder: enable write access
Sourcepub fn with_allowed_paths(self, paths: Vec<String>) -> Self
pub fn with_allowed_paths(self, paths: Vec<String>) -> Self
Builder: set allowed paths
Sourcepub fn with_denied_paths(self, paths: Vec<String>) -> Self
pub fn with_denied_paths(self, paths: Vec<String>) -> Self
Builder: set denied paths
Sourcepub fn with_allowed_commands(self, commands: Vec<String>) -> Self
pub fn with_allowed_commands(self, commands: Vec<String>) -> Self
Builder: set allowed commands
Sourcepub fn with_denied_commands(self, commands: Vec<String>) -> Self
pub fn with_denied_commands(self, commands: Vec<String>) -> Self
Builder: set denied commands
Sourcepub fn check_read(&self, path: &str) -> Result<(), String>
pub fn check_read(&self, path: &str) -> Result<(), String>
Check read permission, returning the denial reason on failure.
§Errors
Returns the denial reason when read is disabled, the path matches a denied pattern, or the path is not in the allowed list.
Sourcepub fn check_write(&self, path: &str) -> Result<(), String>
pub fn check_write(&self, path: &str) -> Result<(), String>
Check write permission, returning the denial reason on failure.
§Errors
Returns the denial reason when write is disabled, the path matches a denied pattern, or the path is not in the allowed list.
Sourcepub fn check_exec(&self, command: &str) -> Result<(), String>
pub fn check_exec(&self, command: &str) -> Result<(), String>
Check exec permission, returning the denial reason on failure.
§Errors
Returns the denial reason when exec is disabled, the command matches a denied pattern, or the command is not in the allowed list.
Sourcepub fn check_path(&self, path: &str) -> Result<(), String>
pub fn check_path(&self, path: &str) -> Result<(), String>
Check whether a path passes the allow/deny rules, returning the specific denial reason on failure.
§Errors
Returns the denial reason when the path matches a denied pattern or is not in the allowed list.
Sourcepub fn check_command(&self, command: &str) -> Result<(), String>
pub fn check_command(&self, command: &str) -> Result<(), String>
Check whether a command passes the allow/deny rules, returning the specific denial reason on failure.
§Security Note
Regex-based command filtering is a heuristic, not a security boundary.
Shell metacharacters (;, &&, |, backticks, $()) allow chaining
arbitrary commands. For example, denied_commands: ["^sudo"] does NOT
block bash -c "sudo rm -rf /". The pre_tool_use hook is the
authoritative gate for command approval.
Invalid deny patterns fail closed (block everything) to prevent misconfigured deny rules from silently allowing dangerous commands.
§Errors
Returns the denial reason when the command matches a denied pattern or is not in the allowed list.
Trait Implementations§
Source§impl Clone for AgentCapabilities
impl Clone for AgentCapabilities
Source§fn clone(&self) -> AgentCapabilities
fn clone(&self) -> AgentCapabilities
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more