Expand description
Tool execution abstraction, shell backend, web scraping, and audit logging for Zeph.
This crate provides the ToolExecutor trait and its concrete implementations:
ShellExecutor— executes bash blocks from LLM responses with sandboxing, blocklists, output filtering, transactional rollback, and audit logging.WebScrapeExecutor— fetches and scrapes web pages via CSS selectors, with SSRF protection and domain policies.CompositeExecutor— chains two executors with first-match-wins dispatch.FileExecutor— reads and writes local files within a sandbox.DiagnosticsExecutor— exposes agent self-diagnostics as a tool.
§Architecture
The primary abstraction is ToolExecutor, an async trait implemented by every backend.
When dynamic dispatch is needed (e.g., storing heterogeneous executors in a Vec), use
ErasedToolExecutor or wrap with DynExecutor.
Tool calls originate from two paths:
- Fenced code blocks — legacy LLM responses containing
```bashor```scrapeblocks dispatched viaToolExecutor::execute. - Structured tool calls — modern JSON tool calls dispatched via
ToolExecutor::execute_tool_call.
§Security
Every executor enforces security controls before execution:
ShellExecutorchecks the command against a blocklist, validates paths against an allowlist sandbox, and optionally requires user confirmation for destructive patterns.WebScrapeExecutorvalidates the URL scheme (HTTPS only), resolves DNS, and rejects private-network addresses (SSRF protection).AuditLoggerwrites a structured JSONL entry for every tool invocation.
§Example
use zeph_tools::{ShellExecutor, ToolExecutor, ShellConfig};
let config = ShellConfig::default();
let executor = ShellExecutor::new(&config);
// Execute a fenced bash block from an LLM response.
let response = "```bash\necho hello\n```";
if let Ok(Some(output)) = executor.execute(response).await {
println!("{}", output.summary);
}Re-exports§
pub use adversarial_gate::AdversarialPolicyGateExecutor;pub use adversarial_policy::PolicyDecision as AdversarialPolicyDecision;pub use adversarial_policy::PolicyValidator;pub use adversarial_policy::parse_policy_lines;pub use anomaly::AnomalyDetector;pub use anomaly::AnomalySeverity;pub use anomaly::is_reasoning_model;pub use audit::AuditEntry;pub use audit::AuditLogger;pub use audit::AuditResult;pub use audit::EgressEvent;pub use audit::VigilRiskLevel;pub use audit::chrono_now;pub use audit::log_tool_risk_summary;pub use cache::CacheKey;pub use cache::ToolResultCache;pub use cache::is_cacheable;pub use composite::CompositeExecutor;pub use config::build_permission_policy;pub use config::validate_sandbox_denied_domains;pub use cwd::SetCwdExecutor;pub use diagnostics::DiagnosticsExecutor;pub use error_taxonomy::ToolErrorFeedback;pub use error_taxonomy::classify_http_status;pub use error_taxonomy::classify_io_error;pub use executor::ClaimSource;pub use executor::DiffData;pub use executor::DynExecutor;pub use executor::ErasedToolExecutor;pub use executor::ErrorKind;pub use executor::FilterStats;pub use executor::MAX_TOOL_OUTPUT_CHARS;pub use executor::TOOL_EVENT_CHANNEL_CAP;pub use executor::ToolCall;pub use executor::ToolError;pub use executor::ToolEvent;pub use executor::ToolEventRx;pub use executor::ToolEventTx;pub use executor::ToolExecutor;pub use executor::ToolOutput;pub use executor::truncate_tool_output;pub use executor::truncate_tool_output_at;pub use file::FileExecutor;pub use filter::CommandMatcher;pub use filter::FilterConfidence;pub use filter::FilterMetrics;pub use filter::FilterResult;pub use filter::OutputFilter;pub use filter::OutputFilterRegistry;pub use filter::sanitize_output;pub use filter::strip_ansi;pub use permissions::PermissionPolicy;pub use policy::PolicyCompileError;pub use policy::PolicyContext;pub use policy::PolicyDecision;pub use policy::PolicyEnforcer;pub use policy_gate::PolicyGateExecutor;pub use registry::ToolRegistry;pub use sandbox::NoopSandbox;pub use sandbox::Sandbox;pub use sandbox::SandboxError;pub use sandbox::SandboxPolicy;pub use sandbox::build_sandbox;pub use sandbox::build_sandbox_with_policy;pub use schema_filter::DependencyExclusion;pub use schema_filter::InclusionReason;pub use schema_filter::ToolDependencyGraph;pub use schema_filter::ToolEmbedding;pub use schema_filter::ToolFilterResult;pub use schema_filter::ToolSchemaFilter;pub use scrape::WebScrapeExecutor;pub use search_code::LspSearchBackend;pub use search_code::SearchCodeExecutor;pub use search_code::SearchCodeHit;pub use search_code::SearchCodeSource;pub use search_code::SemanticSearchBackend;pub use shell::background::BackgroundCompletion;pub use shell::background::BackgroundRunSnapshot;pub use shell::background::RunId;pub use shell::DEFAULT_BLOCKED_COMMANDS;pub use shell::SHELL_INTERPRETERS;pub use shell::ShellExecutor;pub use shell::ShellOutputEnvelope;pub use shell::ShellPolicyHandle;pub use shell::check_blocklist;pub use shell::effective_shell_command;pub use tool_filter::ToolFilter;pub use trust_gate::TrustGateExecutor;pub use utility::UtilityAction;pub use utility::UtilityContext;pub use utility::UtilityScore;pub use utility::UtilityScorer;pub use utility::has_explicit_tool_request;pub use verifier::DestructiveCommandVerifier;pub use verifier::FirewallVerifier;pub use verifier::InjectionPatternVerifier;pub use verifier::PreExecutionVerifier;pub use verifier::UrlGroundingVerifier;pub use verifier::VerificationResult;
Modules§
- adversarial_
gate AdversarialPolicyGateExecutor: wraps an innerToolExecutorand runs an LLM-based policy check before delegating any structured tool call.- adversarial_
policy - LLM-based adversarial policy validator.
- anomaly
- Sliding-window anomaly detection for tool execution patterns.
- audit
- Structured JSONL audit logging for tool invocations.
- cache
- composite
- Composite executor that chains two
ToolExecutorimplementations. - config
- Tool configuration re-exports and runtime helpers.
- cwd
- diagnostics
- domain_
match - Domain pattern matching used by both the web scrape allowlist/denylist and the sandbox egress deny list.
- error_
taxonomy - 12-category tool invocation error taxonomy (arXiv:2601.16280).
- executor
- file
- filter
- Command-aware output filtering pipeline.
- net
- Network utilities for tool crates.
- patterns
- Re-export of injection-detection patterns from
zeph-commonfor backwards compatibility. - permissions
- policy
- Declarative policy compiler for tool call authorization.
- policy_
gate PolicyGateExecutor: wraps an innerToolExecutorand enforces declarative policy rules before delegating any tool call.- registry
- sandbox
- OS-level sandbox abstractions for subprocess tool execution.
- schema_
filter - Dynamic tool schema filtering based on query-tool embedding similarity (#2020).
- scrape
- Web scraping executor with SSRF protection and domain policy enforcement.
- search_
code - shell
- Shell executor that parses and runs bash blocks from LLM responses.
- tool_
filter - trust_
gate - Trust-level enforcement layer for tool execution.
- trust_
level - Re-export of
SkillTrustLevelfromzeph-commonfor backwards compatibility. - utility
- Utility-guided tool dispatch gate (arXiv:2603.19896).
- verifier
- Pre-execution verification for tool calls.
Structs§
- Adversarial
Policy Config - Configuration for the LLM-based adversarial policy agent.
- Anomaly
Config - Configuration for the sliding-window anomaly detector.
- Audit
Config - Configuration for audit logging of tool executions.
- Authorization
Config - OAP-style declarative authorization config.
- Dependency
Config - Configuration for the tool dependency graph feature.
- Destructive
Verifier Config - Configuration for the destructive command verifier.
- Egress
Config - Configuration for egress network event logging.
- File
Config - Per-path read allow/deny sandbox for the file tool.
- Filter
Config - Configuration for output filters.
- Firewall
Verifier Config - Configuration for the firewall verifier.
- Injection
Verifier Config - Configuration for the injection pattern verifier.
- Overflow
Config - Configuration for large tool response offload to
SQLite. - Permission
Rule - Single permission rule: glob
pattern+ action. - Permissions
Config - TOML-deserializable permissions config section.
- Policy
Config - TOML-deserializable policy configuration.
- Policy
Message - Minimal message type for policy LLM calls.
- Policy
Rule Config - A single policy rule as read from TOML.
- PreExecution
Verifier Config - Top-level configuration for all pre-execution verifiers.
- Result
Cache Config - Configuration for the tool result cache.
- Retry
Config - Configuration for tool error retry behavior.
- Sandbox
Config - OS-level subprocess sandbox configuration (
[tools.sandbox]TOML section). - Scrape
Config - Configuration for the web scrape tool.
- Security
Filter Config - Configuration for tool output security filter.
- Shell
Config - Shell-specific configuration: timeout, command blocklist, and allowlist overrides.
- Speculative
Allowlist Config - Shell command regex allowlist for speculative execution.
- Speculative
Config - Top-level configuration for speculative tool execution.
- Speculative
Pattern Config - Pattern-based (PASTE) speculative execution config.
- Tafc
Config - Configuration for Think-Augmented Function Calling (TAFC).
- Tool
Dependency - Dependency specification for a single tool.
- Tool
Name - Strongly-typed tool name label.
- Tools
Config - Top-level configuration for tool execution.
- UrlGrounding
Verifier Config - Configuration for the URL grounding verifier.
- Utility
Scoring Config - Configuration for utility-guided tool dispatch.
Enums§
- Autonomy
Level - Tool access level controlling agent autonomy.
- Default
Effect - Default effect when no policy rule matches.
- Error
Domain - High-level error domain for recovery strategy dispatch.
- Permission
Action - Action a permission rule resolves to.
- Policy
Effect - Effect applied when a policy rule matches.
- Policy
Role - Role for a
PolicyMessage. - Sandbox
Profile - Baseline restriction profile for the OS-level sandbox.
- Skill
Trust Level - Trust tier controlling what a skill is allowed to do.
- Speculation
Mode - Speculative tool execution mode.
- Tool
Error Category - Fine-grained 12-category classification of tool invocation errors.
- Tool
Invocation Phase - Invocation phase in which a tool failure occurred, per arXiv:2601.16280.
Traits§
- Policy
LlmClient - Trait for sending chat messages to the policy LLM.
Functions§
- is_
private_ ip - Returns
trueifaddris a non-routable or private IP address that should be blocked for outbound connections (SSRF defense).