← Back to Pull requests

fix(agent-sandbox): enforce the session ring in HyperLightSandboxProvider.execute_code #4570

Open
unknown opened this pull request with 650 lines diff across 8 files
View on GitHub
unknown unknown commented on Nov 13, 2026 04:17 UTC
Author

Related Issue


Fixes #4569

Problem & Solution


Problem: execute_code reads the session's ring from the stored session config to run the ring subprocess gate and record the call with the RingBreachDetector. Docker and ACA store the SandboxConfig, which has a ring field. HyperLightSandboxProvider stores the HyperlightConfig, which had none, so getattr(cfg, 'ring', None) was always None and the gate was skipped. A Hyperlight session created with SandboxConfig(ring=RING_3_SANDBOX) ran code that Docker and ACA refuse for the same config, no call was recorded for breach detection, and a tripped circuit breaker blocked nothing.

Solution: HyperlightConfig gets a ring field and from_sandbox_config carries SandboxConfig.ring over. The gate in execute_code is unchanged; it now finds the ring it was already looking for.

Behaviour note: with agent-hypervisor installed, a Hyperlight session pinned to a ring that denies subprocess execution (Ring 3) now raises PermissionError on execute_code, as Docker and ACA already do. Sessions created without a ring, or without agent-hypervisor installed, are unchanged.

Impact on Your Work


Found while reviewing the sandbox providers. Anyone who pinned a Hyperlight session to an execution ring got weaker enforcement than the same config gives on Docker or ACA, with no warning.

Timeline


None

Alternatives Considered


  • Keep the ring in a separate per-session dict on the provider: works, but adds a fourth piece of ring state to keep in step with _ring_enforcers and _ring_breach_detectors, while the other providers read it from the session config.

  • Store the original SandboxConfig next to the HyperlightConfig: more state for one field.

  • Refactor the gate, duplicated across three providers, into a shared helper: would have prevented this, but it is a wider change than the bug needs; can follow separately.
  • 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
  • Behaviour note: execute_code now raises for ring-pinned Hyperlight sessions in the cases where Docker and ACA already raise.

    Package(s) Affected


    Governance & security:
  • agent-sandbox
  • Shared / other:

  • docs / root (CHANGELOG.md)
  • Testing

    Unit Testing


    In agent-governance-python/agent-sandbox/tests/test_ring_enforcement_wiring.py, added to TestHyperlightRingEnforcement:
  • test_session_config_keeps_ring: HyperlightConfig.from_sandbox_config carries the ring over, and leaves it None when unset.

  • test_execute_code_ring3_subprocess_denied: a Ring 3 session raises PermissionError, the guest is never run, and the breach detector records the call.

  • test_circuit_breaker_tripped_blocks_execute: a tripped breaker blocks a Ring 2 session before the guest runs.

  • test_execute_code_ring2_permitted: a Ring 2 session runs and the call is recorded.

  • test_execute_code_ring_none_is_noop: no ring, no gate, no ring state.
  • The sessions are created through create_session and nothing is injected into the provider afterwards, so the tests depend on the ring reaching execute_code. The first four fail on main and pass with this change.

    Manual Testing


  • pytest tests/test_ring_enforcement_wiring.py: 18 passed.

  • agent-sandbox suite with the in-repo agent-control-specification 0.4.0b0 and agent-hypervisor on the path, excluding tests/test_docker_integration.py: 545 passed, 37 skipped, 0 failed (540 passed on main).

  • tests/test_docker_integration.py errors on main when a Docker daemon is running (ModuleNotFoundError: No module named 'agent_sandbox.docker_sandbox_provider'); unrelated and not touched here.

  • Before/after script with the real hypervisor.rings classes and a stub SDK injected through sandbox_module=: on main, a Ring 3 Hyperlight session executes the code and the breach detector records 0 calls, while Docker denies and records 1; on this branch Hyperlight denies with the same error as Docker, records 1 call, and no code reaches the guest.

  • ruff check on the touched files: clean.

  • Not run against a real hyperlight-sandbox install or hypervisor; verified with stubbed SDKs only.
  • 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 was used to survey the sandbox package, draft the fix and tests, and draft this description.

    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: MohammadHaroonAbuomar Review duration: 13944m
    All Vouch review confidence checks passed
    Residual risk 0.30 = Change Risk (0.52) × (1 − Review Confidence (0.43)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.52 · 650 lines diff across 8 files
    0.52
    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%
    42%
    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 #4570"
    general weight: 0.35
    Assignees
    Unassigned
    Labels
    risk: low confidence: 43.0% 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: 52% (MEDIUM) · Higher = larger blast radius
    52%
    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: 43.0% · Lower = rushed or shallow review
    43.0%
    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: 29.7% · Safe to merge
    29.7%