Skip to main content
Tools are the primary way agents interact with external systems. A tool that reads data is fundamentally different from a tool that deletes resources — and your security model should reflect this. AFK provides multiple layers of defense for tool security: scoped tool definitions with typed arguments, sandbox profiles that restrict execution capabilities, and policy gates that require human approval for destructive operations. This page demonstrates how to register tools safely, distinguish between read-only and mutating tools, and configure policy gates to protect against unintended destructive actions.

Read-only vs mutating tools

The most important security distinction is between tools that observe (read-only) and tools that act (mutating). Read-only tools are generally safe to allow broadly. Mutating tools should be tightly scoped and policy-gated.
Notice the differences:
  • The read-only tool (get_resource) has a description that explicitly says “Read-only.” This signals to both the model and human reviewers that the tool is safe.
  • The mutating tool (delete_resource) has a description warning about irreversibility. This helps the model understand the severity, and helps policy rules identify destructive operations.

Policy gate setup

Use a PolicyEngine to require human approval before any mutating tool executes:

Sandbox profiles for filesystem tools

For tools that interact with the filesystem or execute commands, use SandboxProfile to restrict their capabilities:

Scoping destructive tools

Follow these principles when registering destructive tools:
  1. Name them clearly. Use verb prefixes that signal intent: delete_, remove_, drop_, update_, modify_. This makes policy rules easy to write and audit.
  2. Type all arguments. Use Pydantic models for argument validation. Never accept freeform dict arguments for mutating operations.
  3. Describe irreversibility. Include “irreversible”, “destructive”, or “permanent” in the tool description. This helps both the model and policy reviewers understand the risk.
  4. Gate with policy rules. Every mutating tool should have a corresponding policy rule. Use request_approval for interactive environments and deny as the fallback in headless mode.
  5. Set cost limits. Use FailSafeConfig.max_tool_calls and max_total_cost_usd to prevent runaway tool usage, especially when the agent has access to APIs with per-call costs.
  6. Audit everything. Policy decisions are emitted as policy_decision events in the run event stream. Persist these events for compliance and debugging.