Bastio
Agent Security

Policy Engine

Configure rules for how AI agent tool calls are handled - allow, block, approve, rate limit, and more.

Policy Engine

Bastio's policy engine lets you define rules for how tool calls are handled. Policies provide fine-grained control over which operations are allowed, blocked, or require human approval.

How Policies Work

When a tool call is validated, Bastio evaluates it against your policies in priority order:

  1. Match - Find policies that match the tool call
  2. Evaluate - Check policy conditions
  3. Apply - Execute the highest-priority matching policy's action

If no policies match, the default action (usually allow) is applied.

Policy Actions

ActionDescription
allowPermit the tool call to execute
blockPrevent execution, return error to agent
require_approvalRoute to human reviewers before execution
rate_limitThrottle requests per time window
sanitizeClean dangerous content from arguments
warnAllow but flag for security review

Creating Policies

Via Dashboard

Navigate to Agent Security > Policies in your dashboard to create and manage policies visually.

Via API

curl -X POST https://api.bastio.com/v1/guard/{proxyId}/policies \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Block Shell Commands",
    "description": "Block all shell execution tools",
    "tool_pattern": "execute_*",
    "action": "block",
    "priority": 100,
    "is_active": true
  }'

Policy Configuration

Basic Fields

FieldTypeDescription
namestringHuman-readable policy name
descriptionstringExplanation of policy purpose
tool_patternstringGlob pattern matching tool names
actionstringAction to take when matched
priorityintegerHigher priority = evaluated first
is_activebooleanWhether policy is enabled

Tool Pattern Matching

Patterns use glob syntax to match tool names:

PatternMatches
execute_shellExact match
execute_*execute_shell, execute_python, etc.
*_fileread_file, write_file, delete_file
*All tools
db_*db_query, db_insert, db_update

Conditions

Add conditions to make policies context-aware:

{
  "name": "Approve High-Risk Tools",
  "tool_pattern": "*",
  "action": "require_approval",
  "conditions": {
    "risk_score_min": 0.7
  }
}

Available Conditions

ConditionTypeDescription
risk_score_minfloatMinimum risk score to match
risk_score_maxfloatMaximum risk score to match
threat_typesarrayMatch specific threat types
argument_patternstringRegex pattern for arguments
time_windowobjectTime-based restrictions
end_user_idstringApply to specific user

Time Windows

Restrict when policies apply:

{
  "name": "Block After Hours",
  "tool_pattern": "execute_*",
  "action": "block",
  "conditions": {
    "time_window": {
      "days": ["saturday", "sunday"],
      "hours_start": 18,
      "hours_end": 9,
      "timezone": "America/New_York"
    }
  }
}

Rate Limiting

Throttle tool call frequency:

{
  "name": "Rate Limit API Calls",
  "tool_pattern": "api_*",
  "action": "rate_limit",
  "rate_limit": {
    "max_requests": 100,
    "window_seconds": 60
  }
}

When rate limited, the response includes retry information:

{
  "action": "block",
  "message": "Rate limit exceeded",
  "retry_after_seconds": 45
}

Policy Templates

Bastio provides pre-built templates for common scenarios:

Strict Production

Maximum security for production environments:

{
  "name": "Strict Production",
  "rules": [
    { "tool_pattern": "execute_*", "action": "block" },
    { "tool_pattern": "*_file", "action": "require_approval" },
    { "tool_pattern": "http_*", "action": "require_approval" },
    { "tool_pattern": "*", "action": "allow", "conditions": { "risk_score_max": 0.3 } },
    { "tool_pattern": "*", "action": "require_approval" }
  ]
}

Development Permissive

Allows most operations with warnings:

{
  "name": "Development Permissive",
  "rules": [
    { "tool_pattern": "*", "action": "warn", "conditions": { "risk_score_min": 0.5 } },
    { "tool_pattern": "*", "action": "allow" }
  ]
}

Code Assistant

Tailored for coding assistants:

{
  "name": "Code Assistant",
  "rules": [
    { "tool_pattern": "read_file", "action": "allow" },
    { "tool_pattern": "write_file", "action": "allow" },
    { "tool_pattern": "execute_shell", "action": "block" },
    { "tool_pattern": "http_*", "action": "block" }
  ]
}

Financial Compliance

PCI-DSS aligned for financial applications:

{
  "name": "Financial Compliance",
  "rules": [
    { "tool_pattern": "*", "action": "block", "conditions": { "threat_types": ["pii_exposure"] } },
    { "tool_pattern": "payment_*", "action": "require_approval" },
    { "tool_pattern": "customer_*", "action": "require_approval" },
    { "tool_pattern": "*", "action": "allow" }
  ]
}

Managing Policies

List Policies

curl https://api.bastio.com/v1/guard/{proxyId}/policies \
  -H "Authorization: Bearer YOUR_API_KEY"

Update Policy

curl -X PUT https://api.bastio.com/v1/guard/{proxyId}/policies/{policyId} \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "is_active": false
  }'

Delete Policy

curl -X DELETE https://api.bastio.com/v1/guard/{proxyId}/policies/{policyId} \
  -H "Authorization: Bearer YOUR_API_KEY"

Reorder Priorities

curl -X POST https://api.bastio.com/v1/guard/{proxyId}/policies/reorder \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "policy_ids": ["pol_high", "pol_med", "pol_low"]
  }'

Policy Evaluation Order

Policies are evaluated in priority order (highest first):

┌─────────────────────────────────────┐
│  Tool Call: execute_shell           │
│  Arguments: {"command": "ls"}       │
└─────────────────────────────────────┘


┌─────────────────────────────────────┐
│  Policy: "Block Dangerous Shells"   │
│  Priority: 100                      │
│  Pattern: execute_*                 │
│  Condition: risk_score > 0.7        │
│  Result: NO MATCH (score=0.15)      │
└─────────────────────────────────────┘


┌─────────────────────────────────────┐
│  Policy: "Allow Safe Shells"        │
│  Priority: 50                       │
│  Pattern: execute_shell             │
│  Condition: risk_score < 0.3        │
│  Result: MATCH → allow              │
└─────────────────────────────────────┘

Best Practices

Next Steps