Skip to content

Conversation

@rasdani
Copy link
Contributor

@rasdani rasdani commented Jan 25, 2026

Description

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

Introduces a reusable sandbox lifecycle layer and refactors agent environments to use it.

  • Add SandboxMixin with ThreadedAsyncSandboxClient, exponential backoff retries, active sandbox tracking, bulk delete, and teardown helpers (exported in experimental/__init__.py)
  • Refactor CliAgentEnv to inherit SandboxMixin: pooled client, retrying create/delete, new tuning params (max_retries, sandbox_client_max_workers/connections), per-turn logging, configurable rollout timeout via get_timeout_seconds, and robust cleanup/teardown
  • Update HarborEnv: derive docker image/CPU/memory/disk from task.toml when not explicitly set, support per-task timeouts, and accept threaded client in setup hooks
  • Docs (environments.md, environments/AGENTS.md): expand CliAgentEnv options (labels, retry/pooling via SandboxMixin), and update experimental envs list

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


async def get_timeout_seconds(self, state: State) -> float:
"""Get timeout for this rollout. Override for per-task timeouts."""
return self.timeout_seconds
Copy link

Choose a reason for hiding this comment

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

Method returns None but callers expect float

High Severity

The get_timeout_seconds method returns self.timeout_seconds which can be None (since timeout_seconds now defaults to None instead of 3600.0), but the return type annotation claims float. Callers don't handle None, causing runtime TypeError when formatting strings with .0f (line 310) or comparing with > (lines 342, 814). While HarborEnv properly overrides with a fallback to 3600.0, the base CliAgentEnv lacks this default.

Additional Locations (2)

Fix in Cursor Fix in Web

@rasdani rasdani force-pushed the daniel/sandbox-mixin branch from e830b56 to a0e709d Compare January 25, 2026 21:59
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 1 potential issue.

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

disk_size_gb: int = 5,
cpu_cores: int = -1, # -1 = use per-task config or default
memory_gb: int = -1, # -1 = use per-task config or default
disk_size_gb: int = -1, # -1 = use per-task config or default
Copy link

Choose a reason for hiding this comment

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

Resource parameters default to -1 breaking sandbox creation

Medium Severity

The cpu_cores, memory_gb, and disk_size_gb parameters now default to -1 instead of their previous values of 1, 2, and 5. These values are passed directly to CreateSandboxRequest in get_sandbox_request without any fallback logic. While HarborEnv overrides this to apply per-task config, the base CliAgentEnv does not provide defaults, potentially causing sandbox creation failures when the API receives invalid negative values.

Additional Locations (1)

Fix in Cursor Fix in Web

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