@@ -626,9 +626,14 @@ def exec_python(
626626 timeout_seconds = timeout_seconds ,
627627 )
628628
629- def delete (self , * , allow_missing : bool = False ) -> DeletionResult :
629+ def delete (
630+ self , * , allow_missing : bool = False , timeout : float | None = None
631+ ) -> DeletionResult :
630632 return self ._client .delete (
631- self .sandbox .name , workspace = self ._workspace , allow_missing = allow_missing
633+ self .sandbox .name ,
634+ workspace = self ._workspace ,
635+ allow_missing = allow_missing ,
636+ timeout = timeout ,
632637 )
633638
634639 def stop (self ) -> SandboxRef :
@@ -1072,15 +1077,21 @@ def list_ids_for_all_workspaces(
10721077 ]
10731078
10741079 def delete (
1075- self , name : str , * , workspace : str , allow_missing : bool = False
1080+ self ,
1081+ name : str ,
1082+ * ,
1083+ workspace : str ,
1084+ allow_missing : bool = False ,
1085+ timeout : float | None = None ,
10761086 ) -> DeletionResult :
1087+ """Delete a sandbox, waiting up to `timeout` (default: client timeout)."""
10771088 response = self ._stub .DeleteSandbox (
10781089 openshell_pb2 .DeleteSandboxRequest (
10791090 workspace_scope = _workspace_scope (workspace ),
10801091 name = name ,
10811092 allow_missing = allow_missing ,
10821093 ),
1083- timeout = self ._timeout ,
1094+ timeout = self ._timeout if timeout is None else timeout ,
10841095 )
10851096 return DeletionResult (
10861097 DeletionOutcome (response .outcome ), response .sandbox_id or None
@@ -1586,13 +1597,18 @@ def __init__(
15861597 workload_template : str | None = None ,
15871598 timeout : float = 30.0 ,
15881599 ready_timeout_seconds : float = 120.0 ,
1600+ delete_timeout_seconds : float | None = None ,
15891601 auto_refresh : bool = True ,
15901602 write_back : bool = True ,
15911603 insecure : bool = False ,
15921604 client_credentials : ClientCredentialsAuth | None = None ,
15931605 ) -> None :
15941606 """Bind a Sandbox context to the active gateway.
15951607
1608+ `delete_timeout_seconds` bounds the delete RPC on exit and defaults to
1609+ `timeout`. Raise it for drivers that hold the delete open while the
1610+ workload terminates.
1611+
15961612 OIDC kwargs (`auto_refresh`, `write_back`, `insecure`, and
15971613 `client_credentials`) forward
15981614 directly to `SandboxClient.from_active_cluster` and have the
@@ -1612,6 +1628,7 @@ def __init__(
16121628 self ._workload_template = workload_template
16131629 self ._timeout = timeout
16141630 self ._ready_timeout_seconds = ready_timeout_seconds
1631+ self ._delete_timeout_seconds = delete_timeout_seconds
16151632 self ._auto_refresh = auto_refresh
16161633 self ._write_back = write_back
16171634 self ._insecure = insecure
@@ -1707,7 +1724,9 @@ def __exit__(self, *args: object) -> None:
17071724 and self ._session is not None
17081725 and self ._client is not None
17091726 ):
1710- result = self ._session .delete (allow_missing = True )
1727+ result = self ._session .delete (
1728+ allow_missing = True , timeout = self ._delete_timeout_seconds
1729+ )
17111730 if result .outcome == DeletionOutcome .ACCEPTED :
17121731 self ._client .wait_deleted (
17131732 self ._session .sandbox .name ,
0 commit comments