Skip to content

Comments

CliAgentEnv: add SandboxMixin, refactor InterceptionServer#847

Merged
willccbb merged 25 commits intomainfrom
daniel/sandbox-mixin2
Feb 7, 2026
Merged

CliAgentEnv: add SandboxMixin, refactor InterceptionServer#847
willccbb merged 25 commits intomainfrom
daniel/sandbox-mixin2

Conversation

@rasdani
Copy link
Contributor

@rasdani rasdani commented Feb 6, 2026

Description

Necessary error handling and retrying to make CliAgentEnv work at scale.

Includes updates from #811

Extract sandbox lifecycle management into a reusable mixin for CliAgentEnv.
Can be used in SandboxEnv too.

Changes

  • Add SandboxMixin class with ThreadedAsyncSandboxClient, retry logic, and bulk cleanup
  • CliAgentEnv now inherits SandboxMixin alongside MultiTurnEnv
  • Add active_sandboxes tracking to prevent orphaned sandboxes on Ctrl+C
  • Add @vf.teardown hooks for bulk sandbox cleanup and client teardown
  • Add retry with exponential backoff for sandbox API calls
  • Use connection-pooled ThreadedAsyncSandboxClient instead of per-call AsyncSandboxClient

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Test improvement

Testing

  • All existing tests pass when running uv run pytest locally.
  • New tests have been added to cover the changes

Checklist

  • My code follows the style guidelines of this project as outlined in AGENTS.md
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • Any dependent changes have been merged and published

Additional Notes


Note

Medium Risk
Touches core sandbox lifecycle/interception paths (CliAgentEnv/HarborEnv) and changes teardown/retry behavior, which could affect stability and cleanup semantics despite added tests.

Overview
Refactors sandbox-backed agent environments to be more reliable at scale by introducing a reusable SandboxMixin that centralizes sandbox creation/deletion, retries with exponential backoff, connection-pooled ThreadedAsyncSandboxClient, and teardown-time bulk cleanup to prevent orphaned sandboxes.

CliAgentEnv now uses SandboxMixin and a new shared InterceptionServer helper (moved into verifiers.utils.interception_utils) to simplify interception/streaming response handling and reduce per-call client creation; HarborEnv/TerminusHarborEnv are updated to the new post_sandbox_setup(state) signature and to run Harbor test/reward collection via background jobs with retry and better error handling (including skipping tests on prior infra errors).

Adds/updates the opencode_harbor environment to support an uploaded system prompt and disabled tool configuration via generated opencode.json, includes a bundled prompt.txt, and adds tests to validate the generated config renders as valid JSON after shell expansion; docs are updated to mention SandboxMixin tuning knobs, and core deps now require prime-tunnel>=0.1.0.

Written by Cursor Bugbot for commit ae3cd0c. This will update automatically on new commits. Configure here.

@rasdani rasdani changed the title experimental: add SandboxMixin. refactor InterceptionServer CliAgentEnv: add SandboxMixin, refactor InterceptionServer Feb 6, 2026
@rasdani rasdani force-pushed the daniel/sandbox-mixin2 branch from 22b09c3 to 8cee0f6 Compare February 6, 2026 20:37
The [tool.hatch.build] include list was missing prompt.txt, which is
referenced by load_environment() via system_prompt_path default
(Path(__file__).parent / 'prompt.txt'). Without it, installing the
package would cause a FileNotFoundError at runtime.

Co-authored-by: rasdani <rasdani@users.noreply.github.com>
@CLAassistant
Copy link

CLAassistant commented Feb 6, 2026

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
3 out of 4 committers have signed the CLA.

✅ rasdani
✅ kcoopermiller
✅ willccbb
❌ cursoragent
You have signed the CLA already but the status is still pending? Let us recheck it.

Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 2 potential issues.

Bugbot Autofix is OFF. To automatically fix reported issues with Cloud Agents, enable Autofix in the Cursor dashboard.

@willccbb willccbb merged commit d82efa5 into main Feb 7, 2026
6 checks passed
@rasdani rasdani mentioned this pull request Feb 8, 2026
13 tasks
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.

5 participants