@@ -680,9 +680,16 @@ def exec_python(
680680 timeout_seconds = timeout_seconds ,
681681 )
682682
683- def delete (self , * , allow_missing : bool = False ) -> DeletionResult :
683+ def delete (
684+ self , * , allow_missing : bool = False , timeout_seconds : float | None = None
685+ ) -> DeletionResult :
686+ # Forward `timeout_seconds` only on opt-in so older clients still work.
687+ extra = {} if timeout_seconds is None else {"timeout_seconds" : timeout_seconds }
684688 return self ._client .delete (
685- self .sandbox .name , workspace = self ._workspace , allow_missing = allow_missing
689+ self .sandbox .name ,
690+ workspace = self ._workspace ,
691+ allow_missing = allow_missing ,
692+ ** extra ,
686693 )
687694
688695 def stop (self ) -> SandboxRef :
@@ -1138,15 +1145,25 @@ def list_ids_for_all_workspaces(
11381145 ]
11391146
11401147 def delete (
1141- self , name : str , * , workspace : str , allow_missing : bool = False
1148+ self ,
1149+ name : str ,
1150+ * ,
1151+ workspace : str ,
1152+ allow_missing : bool = False ,
1153+ timeout_seconds : float | None = None ,
11421154 ) -> DeletionResult :
1155+ """Delete a sandbox.
1156+
1157+ `timeout_seconds` is the gRPC deadline for this call (default: the
1158+ client timeout).
1159+ """
11431160 response = self ._stub .DeleteSandbox (
11441161 openshell_pb2 .DeleteSandboxRequest (
11451162 workspace_scope = _workspace_scope (workspace ),
11461163 name = name ,
11471164 allow_missing = allow_missing ,
11481165 ),
1149- timeout = self ._timeout ,
1166+ timeout = self ._timeout if timeout_seconds is None else timeout_seconds ,
11501167 )
11511168 return DeletionResult (
11521169 DeletionOutcome (response .outcome ), response .sandbox_id or None
@@ -1751,13 +1768,18 @@ def __init__(
17511768 workload_template : str | None = None ,
17521769 timeout : float = 30.0 ,
17531770 ready_timeout_seconds : float = 120.0 ,
1771+ delete_timeout_seconds : float | None = None ,
17541772 auto_refresh : bool = True ,
17551773 write_back : bool = True ,
17561774 insecure : bool = False ,
17571775 client_credentials : ClientCredentialsAuth | None = None ,
17581776 ) -> None :
17591777 """Bind a Sandbox context to the active gateway.
17601778
1779+ `delete_timeout_seconds` bounds the delete RPC on exit and defaults to
1780+ `timeout`. Raise it for drivers that hold the delete open while the
1781+ workload terminates.
1782+
17611783 OIDC kwargs (`auto_refresh`, `write_back`, `insecure`, and
17621784 `client_credentials`) forward
17631785 directly to `SandboxClient.from_active_cluster` and have the
@@ -1777,6 +1799,7 @@ def __init__(
17771799 self ._workload_template = workload_template
17781800 self ._timeout = timeout
17791801 self ._ready_timeout_seconds = ready_timeout_seconds
1802+ self ._delete_timeout_seconds = delete_timeout_seconds
17801803 self ._auto_refresh = auto_refresh
17811804 self ._write_back = write_back
17821805 self ._insecure = insecure
@@ -1872,7 +1895,9 @@ def __exit__(self, *args: object) -> None:
18721895 and self ._session is not None
18731896 and self ._client is not None
18741897 ):
1875- result = self ._session .delete (allow_missing = True )
1898+ result = self ._session .delete (
1899+ allow_missing = True , timeout_seconds = self ._delete_timeout_seconds
1900+ )
18761901 if result .outcome == DeletionOutcome .ACCEPTED :
18771902 self ._client .wait_deleted (
18781903 self ._session .sandbox .name ,
0 commit comments