Get started
Secure your first Python agent.
This example registers one agent, discovers its callable tools, syncs three policies and blocks execution before an unauthorized tool runs.
1. Install
pip install agent-security
2. Configure
AGENT_SECURITY_API_KEY=ask_live_... AGENT_SECURITY_URL=https://agentsecurity.pk
3. Wrap the agent factory
import os
from agent_security import AgentSecurity
security = AgentSecurity(
api_key=os.environ["AGENT_SECURITY_API_KEY"],
base_url=os.getenv("AGENT_SECURITY_URL", "https://agentsecurity.pk"),
)
@security.protect(
"invoice-agent",
permissions={
"invoice.read": "ALLOW",
"invoice.pay": "REQUIRE_APPROVAL",
"invoice.delete": "DENY",
},
)
def build_agent():
return InvoiceAgent(tools=[invoice_read, invoice_pay, invoice_delete])
agent = build_agent()4. Verify behavior
The dashboard will show invoice-agent, its three discovered tools and the code-defined policy. Unknown tools remain denied.
Keep the SDK object alive for the application process and close it during graceful shutdown.