3333 from agentrun .sandbox .aio_sandbox import AioSandbox
3434 from agentrun .sandbox .browser_sandbox import BrowserSandbox
3535 from agentrun .sandbox .code_interpreter_sandbox import CodeInterpreterSandbox
36+ from agentrun .sandbox .custom_sandbox import CustomSandbox
3637 from agentrun .sandbox .model import (
3738 ListSandboxesInput ,
3839 ListSandboxesOutput ,
@@ -169,6 +170,34 @@ def create(
169170 ) -> "AioSandbox" :
170171 ...
171172
173+ @classmethod
174+ @overload
175+ async def create_async (
176+ cls ,
177+ template_type : Literal [TemplateType .CUSTOM ],
178+ template_name : Optional [str ] = None ,
179+ sandbox_idle_timeout_seconds : Optional [int ] = 600 ,
180+ nas_config : Optional ["NASConfig" ] = None ,
181+ oss_mount_config : Optional ["OSSMountConfig" ] = None ,
182+ polar_fs_config : Optional ["PolarFsConfig" ] = None ,
183+ config : Optional [Config ] = None ,
184+ ) -> "CustomSandbox" :
185+ ...
186+
187+ @classmethod
188+ @overload
189+ def create (
190+ cls ,
191+ template_type : Literal [TemplateType .CUSTOM ],
192+ template_name : Optional [str ] = None ,
193+ sandbox_idle_timeout_seconds : Optional [int ] = 600 ,
194+ nas_config : Optional ["NASConfig" ] = None ,
195+ oss_mount_config : Optional ["OSSMountConfig" ] = None ,
196+ polar_fs_config : Optional ["PolarFsConfig" ] = None ,
197+ config : Optional [Config ] = None ,
198+ ) -> "CustomSandbox" :
199+ ...
200+
172201 @classmethod
173202 async def create_async (
174203 cls ,
@@ -179,7 +208,12 @@ async def create_async(
179208 oss_mount_config : Optional ["OSSMountConfig" ] = None ,
180209 polar_fs_config : Optional ["PolarFsConfig" ] = None ,
181210 config : Optional [Config ] = None ,
182- ) -> Union ["CodeInterpreterSandbox" , "BrowserSandbox" , "AioSandbox" ]:
211+ ) -> Union [
212+ "CodeInterpreterSandbox" ,
213+ "BrowserSandbox" ,
214+ "AioSandbox" ,
215+ "CustomSandbox" ,
216+ ]:
183217
184218 if template_name is None :
185219 # todo 可以考虑为用户创建一个模板?
@@ -194,6 +228,7 @@ async def create_async(
194228 from agentrun .sandbox .code_interpreter_sandbox import (
195229 CodeInterpreterSandbox ,
196230 )
231+ from agentrun .sandbox .custom_sandbox import CustomSandbox
197232
198233 if template_type != template .template_type :
199234 raise ValueError (
@@ -224,6 +259,10 @@ async def create_async(
224259 sandbox = AioSandbox .model_validate (
225260 base_sandbox .model_dump (by_alias = False )
226261 )
262+ elif template .template_type == TemplateType .CUSTOM :
263+ sandbox = CustomSandbox .model_validate (
264+ base_sandbox .model_dump (by_alias = False )
265+ )
227266 else :
228267 raise ValueError (
229268 f"template_type { template .template_type } is not supported"
@@ -242,7 +281,12 @@ def create(
242281 oss_mount_config : Optional ["OSSMountConfig" ] = None ,
243282 polar_fs_config : Optional ["PolarFsConfig" ] = None ,
244283 config : Optional [Config ] = None ,
245- ) -> Union ["CodeInterpreterSandbox" , "BrowserSandbox" , "AioSandbox" ]:
284+ ) -> Union [
285+ "CodeInterpreterSandbox" ,
286+ "BrowserSandbox" ,
287+ "AioSandbox" ,
288+ "CustomSandbox" ,
289+ ]:
246290
247291 if template_name is None :
248292 # todo 可以考虑为用户创建一个模板?
@@ -257,6 +301,7 @@ def create(
257301 from agentrun .sandbox .code_interpreter_sandbox import (
258302 CodeInterpreterSandbox ,
259303 )
304+ from agentrun .sandbox .custom_sandbox import CustomSandbox
260305
261306 if template_type != template .template_type :
262307 raise ValueError (
@@ -287,6 +332,10 @@ def create(
287332 sandbox = AioSandbox .model_validate (
288333 base_sandbox .model_dump (by_alias = False )
289334 )
335+ elif template .template_type == TemplateType .CUSTOM :
336+ sandbox = CustomSandbox .model_validate (
337+ base_sandbox .model_dump (by_alias = False )
338+ )
290339 else :
291340 raise ValueError (
292341 f"template_type { template .template_type } is not supported"
@@ -309,7 +358,7 @@ async def stop_by_id_async(cls, sandbox_id: str):
309358 if sandbox_id is None :
310359 raise ValueError ("sandbox_id is required" )
311360 # todo 后续适配后使用 stop()
312- return await cls .__get_client ().delete_sandbox_async (sandbox_id )
361+ return await cls .__get_client ().stop_sandbox_async (sandbox_id )
313362
314363 @classmethod
315364 def stop_by_id (cls , sandbox_id : str ):
@@ -325,7 +374,7 @@ def stop_by_id(cls, sandbox_id: str):
325374 if sandbox_id is None :
326375 raise ValueError ("sandbox_id is required" )
327376 # todo 后续适配后使用 stop()
328- return cls .__get_client ().delete_sandbox (sandbox_id )
377+ return cls .__get_client ().stop_sandbox (sandbox_id )
329378
330379 @classmethod
331380 async def delete_by_id_async (cls , sandbox_id : str ):
@@ -839,10 +888,10 @@ async def stop_async(self):
839888 if self .sandbox_id is None :
840889 raise ValueError ("sandbox_id is required to stop a Sandbox" )
841890 # todo 后续适配后使用 stop()
842- return await self .delete_by_id_async (self .sandbox_id )
891+ return await self .stop_by_id_async (self .sandbox_id )
843892
844893 def stop (self ):
845894 if self .sandbox_id is None :
846895 raise ValueError ("sandbox_id is required to stop a Sandbox" )
847896 # todo 后续适配后使用 stop()
848- return self .delete_by_id (self .sandbox_id )
897+ return self .stop_by_id (self .sandbox_id )
0 commit comments