Policy Playground¶
The Policy Playground is an interactive environment for writing, testing, and debugging OPA policies before activating them. It provides instant feedback with real or sample data.
Accessing the playground¶
- Navigate to Policies > Playground in the left sidebar.
- Alternatively, click Test in Playground from any policy editor.
Layout¶
The playground has a three-panel layout:
| Panel | Purpose |
|---|---|
| Left — Rego Editor | Write or paste your policy code |
| Center — Input | JSON input that simulates what the policy will receive |
| Right — Output | Evaluation result after clicking Evaluate |
┌─────────────────┬─────────────────┬─────────────────┐
│ │ │ │
│ Rego Editor │ Input (JSON) │ Output │
│ │ │ │
│ package mayo. │ { │ { │
│ triage │ "finding": │ "decision": │
│ │ { ... } │ "accept" │
│ decision := │ } │ } │
│ "accept" if { │ │ │
│ ... │ │ │
│ } │ │ │
│ │ │ │
└─────────────────┴─────────────────┴─────────────────┘
Loading sample inputs¶
Instead of writing JSON by hand, you can load real data:
From a finding¶
- Click Load from finding above the input panel.
- Search for a finding by ID, title, or CVE.
- Select a finding — its full input object is loaded.
From a scan¶
- Click Load from scan above the input panel.
- Select a recent scan.
- Choose a finding from the scan results.
From templates¶
- Click Templates above the input panel.
- Choose a template for the policy kind you're testing:
- Triage: finding with CVE, SAST finding, secret detection finding
- Priority: post-triage finding
- Ownership: finding with team context
- Project: GitHub asset, uploaded asset
- PR Scan: PR with new findings, clean PR
Evaluating a policy¶
- Write your Rego in the left panel.
- Set or load an input in the center panel.
- Click Evaluate (or press
Ctrl+Enter/Cmd+Enter). - The output panel shows the result.
Successful evaluation¶
No matching rules¶
If no rules match the input, the output shows only values with explicit defaults:
Info
An empty output means no rule's conditions were satisfied. This is not an error — it means the policy has no opinion about this input.
Validation error¶
If the Rego code has syntax errors, the output panel shows the error with line numbers:
Batch testing¶
Test your policy against multiple inputs at once:
- Click Batch Test in the toolbar.
- Add multiple input cases, each with an expected output.
- Click Run All.
- Results show pass/fail for each case.
┌─────────────────────────────────────────────────────┐
│ Batch Test Results │
├──────────┬────────────┬────────────┬────────────────┤
│ Case │ Expected │ Actual │ Status │
├──────────┼────────────┼────────────┼────────────────┤
│ Case 1 │ "accept" │ "accept" │ ✓ Pass │
│ Case 2 │ "reject" │ "reject" │ ✓ Pass │
│ Case 3 │ "accept" │ (none) │ ✗ Fail │
└──────────┴────────────┴────────────┴────────────────┘
Save test cases
Batch test cases can be saved alongside the policy. They run automatically when the policy is edited, acting as a regression test suite.
Debugging with trace¶
Enable Trace Mode to see how OPA evaluates your policy step by step:
- Toggle Trace in the toolbar.
- Click Evaluate.
- The output panel shows each rule evaluation with pass/fail:
Enter decision := "accept"
| Enter input.finding.severity == "critical"
| | value: true
| Enter input.finding.cve_id != ""
| | value: true (cve_id = "CVE-2026-1234")
| Exit decision := "accept" (matched)
This is invaluable for understanding why a rule is or isn't matching.
Sharing playground sessions¶
Click Share to generate a link to your current playground state (Rego code + input). Share the link with teammates for review.
Warning
Shared links include the input data. Avoid sharing links that contain sensitive finding data outside your organization.
Keyboard shortcuts¶
| Shortcut | Action |
|---|---|
Ctrl+Enter / Cmd+Enter |
Evaluate |
Ctrl+S / Cmd+S |
Save policy (if opened from editor) |
Ctrl+Shift+F / Cmd+Shift+F |
Format Rego code |
Ctrl+/ / Cmd+/ |
Toggle comment |
Playground vs. production¶
The playground runs the same OPA engine as production, with one difference:
print()statements work in the playground for debugging but are stripped in production evaluation.
This means if your policy works in the playground, it will work in production.
Next steps¶
- Writing Rego — Rego syntax reference
- Policy best practices — patterns for effective policies
- Getting started — create your first policy