AgentPolicyForge: From Executable Environments to Policy Benchmarks and Adaptive Guards
Organizations: AWS AI Labs
Abstract
Customized agent deployments define policies over tools, resources, and execution conditions. Providing these policies in the task agent's prompt does not reliably prevent violations. Training a guard requires examples of tool calls that comply with or violate those policies. We introduce AgentPolicyForge, a framework that uses executable environments to construct policy benchmarks and iteratively train policy guards. With this framework, we construct PolicyGym, a dataset across ten policy families using 698 scenarios for training data generation and 254 separate held-out scenarios for human-reviewed test sets. Tool calls are executed and their outcomes recorded to help determine whether they comply with the policy. Every violating case uses a permitted tool, requiring checks of arguments, resources, and context rather than tool identity alone. The case construction process supports iterative guard training: an attacker generates requests using retrieved strategies, and the guard is fine-tuned on balanced, environment-verified examples. Training improves policy enforcement even with a fixed archive. Updating the archive further reduces in-domain attack success compared with keeping it fixed. We compare policy-aware task agent self-regulation with a trained policy guard. On PolicyGym, the final guard-based configuration achieves a 40-44% relative reduction in attack success rate and fewer benign rejections than policy prompting alone.
Figures & tables
| Statistic | Source seeds | In-domain test | Out-of-domain test |
|---|---|---|---|
| Distinct scenarios | 698 | 187 | 67 |
| Seed inputs / episodes | 5,655 | 1,070 | 304 |
| Threat / benign | 2,863 / 2,792 | 535 / 535 | 152 / 152 |
| System | Setting | In-domain | Out-of-domain | ||||||
|---|---|---|---|---|---|---|---|---|---|
| ASR | B-rej. | Rec. ≥2 | FPR ≥2 | ASR | B-rej. | Rec. ≥2 | FPR ≥2 | ||
| Task-agent self-regulation | |||||||||
| Claude Sonnet 5 | Policy-blind | 98.50 | 0.00 | — | — | 99.34 | 0.00 | — | — |
| Claude Sonnet 5 | Policy-aware | 14.77 | 8.79 | — | — | 13.16 | 9.21 | — | — |
| Specialized policy-guard baseline | |||||||||
| PolicyGuard-4B | Binary | 32.52 | 2.80 | 66.22 | 2.43 | 28.29 | 0.66 | 71.18 | 0.89 |
| Setting | ID Test | OOD Test | VIOLA | |||
|---|---|---|---|---|---|---|
| ASR | OB | ASR | OB | ASR | OB | |
| Evolving (R10) | 8.22 | 7.48 | 7.89 | 5.92 | 18.75 | 66.67 |
| Frozen (R10) | 10.84 | 6.73 | 9.21 | 5.92 | 23.96 | 66.67 |
| VIOLA Test+Dev: 1,709 invocation inputs | ||||||
|---|---|---|---|---|---|---|
| Traj. | Model | ASR | Ov.blk | Acc. | F1 | Youden’s J |
| 114 | Qwen3-14B R0 | 27.08 | 61.11 | 67.54 | 79.10 | 11.81 |
| Qwen3-14B R10 | 18.75 | 66.67 | 73.68 | 83.87 | 14.58 | |
Appendix figures & tables15 assets
Supplementary material from the paper’s appendix.
Appendix
| Policy family | Restriction | Illustrative policy | Information used by the check |
|---|---|---|---|
| Time windows | Disallow an operation during a specified time interval. | Transfers are prohibited between 21:00 and 05:00 UTC. | The bound action-time field and the prohibited interval, including intervals crossing midnight. |
| Backdating | Limit how far an operation’s date may precede the reference date. | An entry must not be dated more than 30 days in the past. | The bound date field, fixed reference date, and maximum age in days. |
| Amount limits | Cap the amount of an operation. | A single transfer must not exceed $500. | The relevant amount argument, its units, and the cap. |
| Own-record access | Restrict an operation to the current user’s records. | A record’s owner identifier must match the current user. | The bound owner-identifier argument and trusted current-user identifier. |
| Restricted tables | Exclude a table from the session’s authorization. | The session must not directly write the audit-log table. | The restricted table name, clause scope, and evidence identifying the table targeted by the call. |
| Protected identifiers | Reserve identifiers below a threshold. | Manual operations on account IDs below 1,000 are prohibited. | The bound identifier argument and reserved-range threshold. |
| Verifier | Sonnet 5 | Records |
|---|---|---|
| Compliant | Compliant | 1,930 |
| Violation | Violation | 915 |
| Violation | Compliant | 180 |
| Compliant | Violation | 11 |
| Unknown | Compliant | 146 |
| Unknown | Violation | 129 |
| Object | Train | Test | Exact | Median | P95 |
|---|---|---|---|---|---|
| Natural request | 2,708 | 1,371 | 0 | 0.049 | 0.106 |
| Policy clause | 3,017 | 1,587 | 1 | 0.217 | 0.406 |
| Split | Agree / | Agreement (%) | |
|---|---|---|---|
| ID | 76/78 | 97.44 | 0.949 |
| OOD | 22/22 | 100.00 | 1.000 |
| Overall | 98/100 | 98.00 | 0.960 |
| Round | Active | Prod. | Expl. | Candidate-only bypasses |
|---|---|---|---|---|
| Initial–3 | 18 | 0 | 0 | 0 |
| 4 | 19 | 1 | 0 | 1 |
| 5 | 21 | 2 | 0 | 4 |
| 6 | 22 | 0 | 1 | 0 |
| 7 | 23 | 0 | 1 | 0 |
| 8 | 25 | 1 | 1 | 1 |
| Checkpoint | Split | Proposals | Level 0 | Level 2 | Level 4 | Overblock (%) |
|---|---|---|---|---|---|---|
| Round 0 | in-dom. | 3,521 | 2,752 | 239 | 530 | 3.55 |
| Round 10 | in-dom. | 3,521 | 2,783 | 101 | 637 | 7.48 |
| Round 0 | out-dom. | 955 | 717 | 83 | 155 | 1.97 |
| Round 10 | out-dom. | 955 | 721 | 48 | 186 | 5.92 |
| ID | OOD | ||||
|---|---|---|---|---|---|
| Guard | Block rule | ASR | OB | ASR | OB |
| R0 | Level 4 | 19.63 | 3.55 | 17.11 | 1.97 |
| Level | 3.18 | 14.58 | 4.61 | 18.42 | |
| Fixed R10 | Level 4 | 10.84 | 6.73 | 9.21 | 5.92 |
| Level | 2.80 | 12.52 | 1.97 | 17.11 | |
| Evolving R10 | Level 4 | 8.22 | 7.48 | 7.89 | 5.92 |
| ID | OOD | ||||
|---|---|---|---|---|---|
| Qwen3 | Round | ASR | OB | ASR | OB |
| 14B | R0 | 19.63 | 3.55 | 17.11 | 1.97 |
| R10 | 8.22 | 7.48 | 7.89 | 5.92 | |
| 8B | R0 | 33.08 | 2.80 | 39.47 | 2.63 |
| R10 | 21.12 | 10.28 | 20.39 | 9.87 | |
| ID | OOD | |||
|---|---|---|---|---|
| Supervision | ASR | OB | ASR | OB |
| LLM | 8.22 | 7.48 | 7.89 | 5.92 |
| Verifier | 11.40 | 6.54 | 11.18 | 2.63 |
| Evaluation view | Split | ASR | Ov.blk | Accuracy | F1 | Recall | FPR | Parse |
|---|---|---|---|---|---|---|---|---|
| Online | in-dom. | 32.52 | 2.80 | 92.22 | 74.39 | 66.22 | 2.43 | 100.00 |
| Online | out-dom. | 28.29 | 0.66 | 94.14 | 81.21 | 71.18 | 0.89 | 100.00 |
| Trajectory | in-dom. | 32.71 | 2.62 | 82.34 | 79.21 | 67.29 | 2.62 | 100.00 |
| Trajectory | out-dom. | 28.29 | 0.66 | 85.53 | 83.21 | 71.71 | 0.66 | 100.00 |
| Split | Error type | Episodes | Frozen errors | Evolving errors | Repaired | New errors | Clustered 95% CI (pp) |
|---|---|---|---|---|---|---|---|
| In-domain | Missed violation | 535 | 58 | 44 | 15 | 1 | |
| In-domain | Benign block | 535 | 36 | 40 | 1 | 5 | |
| Out-of-domain | Missed violation | 152 | 14 | 12 | 2 | 0 | |
| Out-of-domain | Benign block | 152 | 9 | 9 | 2 | 2 |
| Comparator | Error type | Trajectories | Comparator errors | Evolving errors | Repaired | New errors |
|---|---|---|---|---|---|---|
| Frozen archive | Missed violation | 96 | 23 | 18 | 8 | 3 |
| Frozen archive | Benign false alarm | 18 | 12 | 12 | 2 | 2 |
| Guard | ASR | Over-block | FN / 90 | FP / 90 |
|---|---|---|---|---|
| R0 | 20.00 | 34.44 | 18 | 31 |
| R10 | 2.22 | 47.78 | 2 | 43 |
| Model | Rows | Acc. | ASR | Ov.blk | F1 | FN | FP |
| Full | |||||||
| R0 | 12,000 | 90.633 | 9.927 | 8.954 | 89.075 | 505 | 619 |
| R10 | 12,000 | 90.817 | 9.927 | 8.636 | 89.266 | 505 | 597 |
| Visible-decidable | |||||||
| R0 | 4,640 | 96.638 | 0.367 | 4.282 | 93.299 | 4 | 152 |
| R10 | 4,640 | 96.961 | 0.275 | 3.887 | 93.909 | 3 | 138 |
| Framework | Task or policy construction | Evidence and supervision | Use in evaluation or training |
|---|---|---|---|
| ToolEmu ( Ruan et al., 2024 ) | Tool-use scenarios for identifying agent risks | LM-emulated tool execution and LM safety evaluation, with human assessment | Risk evaluation across tools and scenarios |
| AgentDojo ( Debenedetti et al., 2024 ) | Agent tasks and prompt-injection attacks in extensible tool environments | Agent executions evaluated for task utility and attack success | Evaluation of tasks, defenses, and adaptive attacks |
| PolicyGuard ( Wen et al., 2026a ) | Policies paired with web trajectories and prefixes | Policy-compliance supervision in PolicyGuardBench | Training and evaluation of a policy guard |
| BraveGuard ( Feng et al., 2026a ) | Emerging threats instantiated as executable computer-use tasks | Collected rollouts with trajectory-level guard supervision | Repeatable threat discovery, data collection, and guard training |
| HazardAuditor ( Feng et al., 2026b ) | Executable threats across heterogeneous computer-use agents | Normalized agent events and deterministic safety outcomes | Cross-framework supervision and GuardPO training |
| AgentPolicyForge | Conditional policies bound to tools, resources, and state; compliant and violating calls | Execution records, rule checks, LLM targets, and human-reviewed test labels | Fixed policy tests, multi-round guard training, and validated strategy updates |
Tool Access Control for LLM Agents
Tool access control for LLM agents limits which tools, resources, and actions agents may use, and under what conditions.
See all 221 papers