Skip to content

Add policy engine example scripts for agent permissions testing [CC-18, CC-19, CC-20, CC-21]#691

Open
vhrahulkumar wants to merge 12 commits into
digitalocean:mainfrom
vhrahulkumar:OHS_policy_engine_examples
Open

Add policy engine example scripts for agent permissions testing [CC-18, CC-19, CC-20, CC-21]#691
vhrahulkumar wants to merge 12 commits into
digitalocean:mainfrom
vhrahulkumar:OHS_policy_engine_examples

Conversation

@vhrahulkumar

Copy link
Copy Markdown

Summary

Adds four standalone Python scripts to examples/agents/ that exercise the permissions: block of the agent spec (policy engine). These were written and validated against production microVM as part of the pydo PR #680 UAT.

Reference Doc

Script What it tests
policy_auto_allow.py touch * → allow executes without any HITL prompt
policy_auto_deny.py ls * → deny blocks the command automatically, no prompt
policy_hitl_ask.py defaultAction: ask gates an unmatched command; tests both approve and reject resolution paths
policy_write_interception.py Write/Edit (non-Bash) tool call is intercepted under defaultAction: ask

How the scripts work

  • Each script loads the base AGENT_SPEC YAML, injects a permissions: block, and creates a short-lived session (auto-destroyed on exit).
  • HITL resolution uses a callable policy so the run never hangs, the callback records whether HITL fired and resolves it immediately.
  • Assertions print PASS / FAIL with a reason and exit non-zero on failure, so they can be wired into a test runner.

SSharma-10 and others added 12 commits June 23, 2026 16:06
… interface (digitalocean#682)

* Create hosted-agent sessions from an agents.yaml manifest

The harness-api backend provisions a session entirely from the agent
spec, so replace the legacy JSON create(agent_kind=...) with
create_from_manifest(), which uploads the manifest verbatim as
Content-Type: application/x-yaml. The spec defines the runtime adapter,
sandbox, env vars, and egress; there are no other arguments.

- Add create_from_manifest() to the sync and async session clients,
  sharing manifest-normalization and YAML media-type helpers.
- Remove the now-unsupported create(agent_kind=...) path.
- Point the create_session.py example at a spec file and add
  session_e2e.py demonstrating the full create -> attach (send a
  prompt, stream SSE back) -> destroy flow.
- Cover manifest upload in the sync and new async unit tests; drop the
  legacy create test.

* regenerate fix

* fix

---------

Co-authored-by: SSharma-10 <shivanisharma@digitalocean.com>
Four standalone scripts exercising the permissions block:
- policy_auto_allow.py  — touch * → allow runs without HITL
- policy_auto_deny.py   — ls * → deny blocks without HITL prompt
- policy_hitl_ask.py    — defaultAction: ask gates unmatched commands;
                          tests both approve and reject resolution paths
- policy_write_interception.py — Write/Edit (non-Bash) tool intercepted
                                 under defaultAction: ask
All scripts load the base AGENT_SPEC, inject a permissions block, and
assert pass/fail without external YAML files.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants