← Back to Pull requests

fix(openshell): make the [openshell] extra enforce ACS policy again #4166

Open
unknown opened this pull request with 650 lines diff across 8 files
View on GitHub
unknown unknown commented on Sep 27, 2026 20:18 UTC
Author

Related Issue

None. Replaces #3728, which carried six weeks of CI history and follow-up comments on the same branch. The sections below are filled in because no issue is linked.

Problem & Solution

Problem. pip install agent-governance-toolkit-integrations[openshell] installs an openshell_agentmesh module that does nothing except emit a deprecation warning. The v5 migration removed the working adapter and never replaced it with an ACS one, so the extra we still advertise is empty.

Solution. GovernanceSkill and governed_shell are back, now backed by ACS. Every subprocess.run, subprocess.Popen, os.system and os.popen inside a governed_shell scope goes through session.pre_tool_call as shell.execute before the process starts. The policy-check CLI and the consolidated-package entry point come back with it.

skill = GovernanceSkill.from_manifest("acs.yaml")
with governed_shell(skill):
    subprocess.run(["rm", "-rf", "/data"])  # raises ShellPolicyViolation on DENY

The policy target reports the program that will actually run:

  • executable= passed by keyword or positionally (Popen(["x", f], -1, "/bin/rm")) is what policy sees. Every positional after args is bound to its Popen name before the command is frozen, so a positional shell=True is evaluated as a shell command too. A value given both positionally and by keyword raises TypeError before evaluation, as Popen does.

  • On a TRANSFORM verdict the caller's executable= is dropped, so the transformed argv[0] (or the default shell) runs.

  • With shell=True, os.system and os.popen, executable is the shell. A rule keyed on executable alone does not see the program named in the string; policies must match on command. The README and the _policy_executable docstring say so.
  • Where to look (15 minutes)

    About 480 lines of production code in skill.py and cli.py, about 940 lines of tests, the rest docs and CI wiring.

  • skill.py:106: if policy evaluation throws, the command does not run. The broad except Exception is on purpose.

  • skill.py:109: any verdict that does not permit (DENY, legacy ESCALATE) blocks before the subprocess starts.

  • skill.py:111-117: a TRANSFORM with a malformed target raises instead of running the original command.

  • skill.py:226-292: positional binding, freezing, and the transform rule for executable, shared by the run and Popen wrappers.

  • skill.py:140-193: nested and concurrent scopes are tracked in a ContextVar, and the four builtins are restored by reference even when the governed body raises.
  • Out of scope: v4 policy objects still need migrating to ACS, and this does not add a Vertex provider.

    Impact on Your Work

    OpenShell sandboxes are where agents run shell commands, and the [openshell] extra is how our docs tell users to govern them. Today that extra installs a no-op, so anyone following the docs gets no enforcement and no error telling them so. This puts enforcement back behind the same import path.

    Timeline

    None.

    Alternatives Considered

  • Remove the [openshell] extra instead. That breaks the documented install path and leaves OpenShell users with nothing to migrate to.

  • Govern only at the OpenShell sandbox boundary. That loses the per-command context (argv, cwd, agent and session ids) the ACS policy needs, and it cannot apply a TRANSFORM.

  • Patch only subprocess.Popen. os.system does not go through Popen, so it would run ungoverned.
  • Type of Change


  • Bug fix (non-breaking change that fixes an issue)

  • New feature (non-breaking change that adds functionality)

  • Breaking change (fix or feature that would cause existing functionality to change)

  • Documentation update

  • Maintenance (dependency updates, CI/CD, refactoring)

  • Security fix
  • Package(s) Affected


    Core & runtime:
  • agent-governance-toolkit-core

  • agent-primitives

  • agent-os

  • agent-mesh

  • agent-runtime

  • agent-sre

  • agent-compliance
  • Governance & security:

  • agent-mcp-governance

  • agent-rag-governance

  • agent-sandbox

  • agent-discovery

  • agt-policies

  • policy-engine
  • Platform & tooling:

  • agent-hypervisor

  • agent-lightning

  • agent-marketplace

  • agent-governance-toolkit-cli

  • agent-governance-toolkit-integrations

  • agent-governance-toolkit-protocols

  • agentmesh-integrations (framework integrations)
  • CLI plugins:

  • agent-governance CLI plugins (copilot-cli / claude-code / opencode / antigravity-cli)
  • Shared / other:

  • schemas

  • action (GitHub Action)

  • examples

  • docs / root
  • Testing

    Unit Testing

    agentmesh-integrations/openshell-skill/tests/test_skill.py covers the verdict gate (ALLOW, WARN, DENY, ESCALATE, TRANSFORM), fail-closed evaluation, approval resolution, nested and concurrent scopes, restore on exception, argv freezing for any iterable, path-like cwd and executable, shell strings, and the CLI.

    Added for the latest review:

  • test_positional_executable_is_what_policy_sees[run|popen]: a policy denying executable rm blocks Popen(["x", f], -1, "/bin/rm") and the same call through run, and f survives.

  • test_executable_given_twice_raises_before_evaluation[run|popen]: positional plus keyword executable raises TypeError with no policy call.

  • test_positional_shell_is_what_policy_sees: the ninth positional shell=True is reported as a shell command.

  • test_transform_drops_caller_executable (4 cases): keyword and positional executable= pointing at a missing program, transformed to a Python argv that writes a marker. The marker is written, so the transformed argv ran.

  • test_transform_to_echo_does_not_run_caller_rm[run|popen]: executable="/bin/rm" with a transform to ["echo", f] leaves f in place. POSIX only.
  • All nine new cases that run on Windows fail against the previous head and pass now.

    Manual Testing

    Locally on Windows with Python 3.12 and the ACS contract stub (OPENSHELL_TEST_STUB_ACS=1): 55 passed, 3 skipped (the native ACS test and the two POSIX /bin/rm cases). The native OpenShell CI job builds ACS and runs the full file on Linux. On the previous head, 144 checks passed and 7 were skipped. ruff check . --select E,F,W --ignore E501 is clean.

    Checklist


  • I have linked a related issue above, or completed "Problem & Solution", "Impact on Your Work", and "Alternatives Considered"

  • My code follows the project style guidelines (ruff check)

  • I have added tests that prove my fix/feature works

  • All new and existing tests pass (pytest)

  • I have updated documentation as needed

  • I have signed the Microsoft CLA
  • Attribution & Prior Art


  • This contribution does not contain code copied or derived from other projects without attribution

  • Any external projects that inspired this design are credited in code comments or documentation

  • If this PR implements functionality similar to an existing open-source project, I have listed it below
  • Prior art / related projects (if any):

    AI Assistance


  • I can explain every meaningful change in this PR: what it does, why, and what tradeoffs were considered

  • I have run tests and verification appropriate for this change

  • No part of this PR was autonomously submitted by an AI agent without my review

  • I have not used AI to generate review comments on others' PRs
  • If AI tools materially shaped this change, briefly note what was used:

    Claude Code wrote most of the code and tests in this PR, which is why the commits carry a Claude co-author trailer. I reviewed every change and ran the tests before pushing.

    IP, Patents, and Licensing


  • This contribution does not implement patent-pending or patent-encumbered techniques

  • This contribution does not require an NDA or licensing agreement to understand or use

  • Any AI tools used have terms compatible with the MIT License
  • Diff: 650 lines (+487 / -163) across 8 files Reviewer: prayagupa Review duration: 80611m
    All Vouch review confidence checks passed
    Residual risk 0.33 = Change Risk (0.59) × (1 − Review Confidence (0.45)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.59 · 650 lines diff across 8 files
    0.59
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    44%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.388
    Shallow Review Depth shallow_review_depth
    0.344
    Real PR Conversation Timeline
    1 comments
    "Review active on #4166"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 44.7% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 59% (MEDIUM) · Higher = larger blast radius
    59%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 44.7% · Lower = rushed or shallow review
    44.7%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 32.6% · Safe to merge
    32.6%