Python: Bound Hyperlight output attachments - #8176
Conversation
There was a problem hiding this comment.
🟡 Changes recommended
Output enumeration remains unbounded, and intermediate path components remain vulnerable to TOCTOU replacement.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
Hardens Hyperlight output attachments against host-memory exhaustion with finite invocation-scoped quotas.
Changes:
- Adds configurable file-count and byte limits.
- Uses descriptor validation and bounded reads before encoding.
- Adds documentation and unit/integration coverage.
File summaries
| File | Description |
|---|---|
python/packages/hyperlight/agent_framework_hyperlight/_execute_code_tool.py |
Implements quota enforcement and bounded materialization. |
python/packages/hyperlight/agent_framework_hyperlight/_provider.py |
Forwards quota configuration. |
python/packages/hyperlight/tests/hyperlight/test_hyperlight_codeact.py |
Tests limits, failures, and propagation. |
python/packages/hyperlight/README.md |
Documents defaults and configuration. |
Review details
- Files reviewed: 4/4 changed files
- Comments generated: 2
- Review effort level: Balanced
💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.
There was a problem hiding this comment.
MAF Automated Review — Iteration 1
Result: Findings reported
Scope: full PR (1 commit(s)): 5263ed9450de
Model: gpt-5.6-sol-fast
Overview
The change adds finite invocation-scoped attachment quotas, validates their public configuration, performs descriptor-based bounded reads, and delays base64 materialization until all outputs pass validation. Tests cover sparse files, file growth, cumulative accounting, shared-registry behavior, and structured handling of read and encoding allocation failures. Two residual gaps remain: output discovery is still unbounded before the new file-count gate, and accepted extreme byte limits can raise an uncaught OverflowError.
Reviewed the supplied pull-request change set across correctness, security/reliability, architecture, and failure behavior.
2 verified findings remained after source verification (1 high, 1 medium) across 1 file. Details are attached to the affected lines below.
Affected areas: python/packages/hyperlight/agent_framework_hyperlight/_execute_code_tool.py
5263ed9 to
56f4d57
Compare
56f4d57 to
a46b303
Compare
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
a46b303 to
0b3477e
Compare
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Motivation & Context
Untrusted code in a filesystem-enabled Hyperlight sandbox can create output files with attacker-controlled logical sizes. Reading those files without quotas can allocate proportional host memory and then allocate again while constructing inline base64 data URIs, allowing a sparse guest file to exhaust the trusted host process.
This change bounds Agent Framework's output attachment discovery and materialization, and surfaces quota or allocation failures as structured execution errors while preserving sandbox stdout. Guest-side filesystem creation and output-tree cleanup limits remain the responsibility of Hyperlight.
Description & Review Guide
HyperlightExecuteCodeToolandHyperlightCodeActProvider; validates and forwards them through run-scoped tools and serializable state; uses only bounded streaming filesystem discovery rather than the backend's eager output listing; bounds every entry visited during attachment discovery, nesting depth, and simultaneously open scanner set; opens the output root and path components through pinned no-follow directory descriptors where supported; verifies identities and logical size on the opened descriptor; performs verified-size-plus-one reads capped by the remaining allowances; and delaysContent.from_datauntil every output has passed validation and byte limits./outputchildren. The PR does not attempt to bound guest file/tree creation or recursive cleanup of an already-created tree; those controls belong in Hyperlight.Related Issue
Related to #8055. This focused hardening was prompted by a privately shared Hyperlight output-handling report; it intentionally leaves the framework-level artifact-store design for future work and guest filesystem creation limits to Hyperlight, and therefore does not close #8055. No competing PR for this Hyperlight fix was found.
Contribution Checklist
breaking changelabel (or add "[BREAKING]" to the title prefix, before or after any language prefix) — a workflow keeps the label and title prefix in sync automatically.