Skip to content

fix: mirror CLI VM sandbox guards in SDK#538

Merged
DamianB-BitFlipper merged 5 commits intomainfrom
fix/sdk-vm-sandbox-parity
Apr 20, 2026
Merged

fix: mirror CLI VM sandbox guards in SDK#538
DamianB-BitFlipper merged 5 commits intomainfrom
fix/sdk-vm-sandbox-parity

Conversation

@DamianB-BitFlipper
Copy link
Copy Markdown
Contributor

@DamianB-BitFlipper DamianB-BitFlipper commented Apr 20, 2026

Summary

  • mirror the CLI's VM sandbox guard behavior in the prime-sandboxes SDK for port exposure and SSH-related methods
  • add public is_vm helpers to the sync and async sandbox clients so SDK consumers can branch on VM-backed sandboxes explicitly
  • add focused unit coverage for the new VM guard paths and cache-backed is_vm behavior

Testing

  • cd packages/prime-sandboxes && python -m pytest tests/test_vm_guards.py -x --no-header
  • cd packages/prime-sandboxes && python -m pytest tests/test_command_transport_selection.py tests/test_models.py tests/test_client_retry.py tests/test_gateway_error_mapping.py tests/test_vm_guards.py --no-header
  • cd packages/prime-sandboxes && python -m ruff check src/prime_sandboxes/sandbox.py tests/test_vm_guards.py

Note

Medium Risk
Changes runtime behavior for VM-backed sandboxes by turning previously-attempted operations into immediate APIErrors, which could break callers relying on prior (failing) gateway behavior. Scope is limited to expose/SSH paths and is covered by new unit tests.

Overview
Mirrors CLI behavior by failing fast on VM-backed sandboxes: SandboxClient/AsyncSandboxClient now guard port exposure and SSH operations (expose, unexpose, list_exposed_ports, create_ssh_session, close_ssh_session) and raise a clear APIError instead of issuing HTTP requests.

Adds public is_vm() helpers (sync + async) that delegate to the auth cache (with cold-cache fallback to GET /sandbox/<id>), and introduces test_vm_guards.py to assert guards prevent HTTP calls on VMs while container-backed sandboxes still proceed normally.

Reviewed by Cursor Bugbot for commit 5240e48. Bugbot is set up for automated code reviews on this repo. Configure here.

@DamianB-BitFlipper
Copy link
Copy Markdown
Contributor Author

@cursoragent review

@DamianB-BitFlipper
Copy link
Copy Markdown
Contributor Author

@codex review

@cursor
Copy link
Copy Markdown

cursor Bot commented Apr 20, 2026

Findings (ordered by severity)

No issues found.

I reviewed the VM-guard and is_vm changes in:

  • packages/prime-sandboxes/src/prime_sandboxes/sandbox.py (notably around is_vm/guard methods at ~L544-562 and ~L1421-1438, and guarded call sites at ~L1251-1296 and ~L2156-2201)
  • packages/prime-sandboxes/tests/test_vm_guards.py

The behavior aligns with CLI guard semantics (packages/prime/src/prime_cli/commands/sandbox.py around _guard_vm_unsupported and its call sites).

Open questions / assumptions

  • Assumed backend GET /sandbox/<id> continues returning a shape compatible with Sandbox.model_validate(...) for is_vm fallback paths.
  • Minor test gap (non-blocking): async cold-cache is_vm fallback/caching path is less directly covered than sync cold-cache behavior.

Change summary (secondary)

  • No code changes were needed from this review pass.
  • Validation run results:
    • python3 -m pytest tests/test_vm_guards.py -x --no-header ✅ (21 passed)
    • python3 -m pytest tests/test_command_transport_selection.py tests/test_models.py tests/test_client_retry.py tests/test_gateway_error_mapping.py tests/test_vm_guards.py --no-header ✅ (56 passed)
    • python3 -m ruff check src/prime_sandboxes/sandbox.py tests/test_vm_guards.py

Optional environment optimization: since I installed prime-sandboxes dev deps to run checks, you could run an env setup agent with:
“Preinstall packages/prime-sandboxes test/lint deps (pip install -e .[dev]) in the cloud image so future agents can run pytest/ruff without bootstrap.”

Open in Web Open in Cursor 

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 43bd41a5ec

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread packages/prime-sandboxes/src/prime_sandboxes/sandbox.py
d42me
d42me previously approved these changes Apr 20, 2026
Base automatically changed from fix-images-list to main April 20, 2026 10:44
@DamianB-BitFlipper DamianB-BitFlipper dismissed d42me’s stale review April 20, 2026 10:44

The base branch was changed.

@DamianB-BitFlipper DamianB-BitFlipper merged commit 5b12dee into main Apr 20, 2026
19 of 20 checks passed
@DamianB-BitFlipper DamianB-BitFlipper deleted the fix/sdk-vm-sandbox-parity branch April 20, 2026 16:11
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.

2 participants