Repository navigation
Audit: sandbox lifecycle semantics are inconsistent across the seven backends — toward a shared lifecycle contract #3287
Koawa265Richard31
started this conversation in
Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Summary
Summary
AgentScope ships seven remote/local workspace backends behind one shared
SandboxedWorkspaceBasecontract. The lifecycle semantics behind the contract are not uniform — every capability this issue examined (lease renewal, death detection, recovery, failure cleanup) is implemented at a different level, or not at all, per backend. Each backend is locally reasonable; there is no shared contract that guarantees "an active session's sandbox does not die silently, and a failed initialization does not leak billable resources."Evidence matrix from code reading on⚠️ partial · ❌ absent · N/A not applicable.
main72f3f6fa(every cell verified against the source file; verification notes at the end). ✅ wired ·is_alive— written only at__init__/__aenter__/__aexit__(_base.py:327,536,544); no write point for server-side reclamation (#3208)is_runningpoll only (_e2b_workspace.py:196); no in-turn health checkSandboxStatehandling — started/stopped/paused/starting/stopping/pausing/resuming normalized, error states filtered by recoverability (_daytona_workspace.py:284,330)Running/Pending/Failed/Unknown/Succeededdispatch,deletion_timestamprace handling, rebuild-on-unknown (_k8s_workspace.py:346)_docker_workspace.py:6-10)_applecontainer_workspace.py:157)_opensandbox_workspace.py, #2488 docstring: "Ephemeral workspace data may have been lost")connect()auto-resumes; resume blocked until envdis_runningpasses (_e2b_workspace.py:196-240)start(), transitional → wait-then-start, recoverable error →recover()(_daytona_workspace.py:330)_k8s_workspace.py:346-421)workdirsurvives (opt-in persistence,_docker_workspace.py:8-10)_applecontainer_workspace.py:157)pause()andclose()failures logged separately, then handle dropped (_opensandbox_workspace.py:168-186)pause()failure logged, handle dropped (_e2b_workspace.py:169-180)stop()and client-close failures logged separately (_daytona_workspace.py:190-214)_k8s_workspace.py:203-237)_bubblewrap_workspace.py:302)_docker_workspace.py:149)_applecontainer_workspace.py:193)initialize()override tears down partial resources and re-raises, incl.CancelledError(PR #3274)_provision_backendleaves the sandbox running and unmanageddelete_pvc_on_closedefaultsFalseso even normal close keeps the PVCasyncio.shield-wrapped cleanup survives cancellation (_bubblewrap_workspace.py:289)set_timeout()("can extend or reduce the sandbox timeout... from the last call to.set_timeout",e2b/sandbox_async/main.py:564) andlifecycle: {on_timeout: "pause", auto_resume}— never called by AgentScopeset_autostop_interval/set_ttl/set_auto_pause_interval/recover()(daytona/_async/sandbox.py:726-858) — never called;auto_stop_intervaldefaults to 15 min idle-stop and is not exposed as config (_daytona_workspace.py_create_paramsdocstring: "TTL ... not exposed here; Daytona defaults apply")Why this matters (three concrete failure shapes, all currently reachable)
_create_params(_daytona_workspace.py) sets only labels/public/env —auto_stop_intervalis not exposed, so the SDK default (15 min idle → auto-stop) applies to every Daytona workspace. An agent turn with a long autonomous loop and no SDK interaction for 15 minutes gets its sandbox stopped mid-turn. fix(workspace): recover expired OpenSandbox sandboxes #2488's docstring advice ("configure a longer lease") cannot be followed — there is nothing to configure.delete_pvc_on_closealso defaults toFalse, so even successful closes leave PVCs behind unless the deployer opts in.What each backend already does right (patterns a contract should unify)
_k8s_workspace.py:346): pod-phase state machine — explicit phases,deletion_timestamprace handling, conservative rebuild-on-unknown-phase. The most complete death detection in the repo._daytona_workspace.py:284): explicitSandboxStateclassification incl. transitional states (stopping → wait → start), conservative filtering of unrecoverable errors._e2b_workspace.py:196): attach-time routing-readiness probe (is_runningpoll with exponential backoff)._bubblewrap_workspace.py:289): init-failure cleanup underasyncio.shield(survives cancellation).Proposal
SandboxedWorkspaceBase(opt-in; lease-less/local backends inherit safe defaults):prepare_for_reuse() -> bool— already landed in shape via fix(workspace): renew OpenSandbox leases during long turns #3274 onWorkspaceBase; formalize as the backend contract (K8s/Daytona/E2B override to renew or verify, local/Docker keep the default);alive / expired / unavailable) replacing the bareis_alivebool, updated by detection, not only by user actions;auto_stop_interval/ttlfirst (currently hard-silently at SDK defaults), E2Bset_timeoutsecond.Scope boundaries
Related
Investigation and proposal preparation used AI assistance; I read the lifecycle implementations of all seven remote/local backends myself and verified every matrix cell against source (files and line refs available on request).
All reactions