1111from agentrun .utils .model import BaseModel
1212
1313if TYPE_CHECKING :
14+ from agentrun .sandbox .aio_sandbox import AioSandbox
1415 from agentrun .sandbox .browser_sandbox import BrowserSandbox
1516 from agentrun .sandbox .code_interpreter_sandbox import CodeInterpreterSandbox
1617 from agentrun .sandbox .model import (
@@ -78,14 +79,25 @@ async def create_async(
7879 ) -> "BrowserSandbox" :
7980 ...
8081
82+ @classmethod
83+ @overload
84+ async def create_async (
85+ cls ,
86+ template_type : Literal [TemplateType .AIO ],
87+ template_name : Optional [str ] = None ,
88+ sandbox_idle_timeout_seconds : Optional [int ] = 600 ,
89+ config : Optional [Config ] = None ,
90+ ) -> "AioSandbox" :
91+ ...
92+
8193 @classmethod
8294 async def create_async (
8395 cls ,
8496 template_type : TemplateType ,
8597 template_name : Optional [str ] = None ,
8698 sandbox_idle_timeout_seconds : Optional [int ] = 600 ,
8799 config : Optional [Config ] = None ,
88- ) -> Union ["CodeInterpreterSandbox" , "BrowserSandbox" ]:
100+ ) -> Union ["CodeInterpreterSandbox" , "BrowserSandbox" , "AioSandbox" ]:
89101
90102 if template_name is None :
91103 # todo 可以考虑为用户创建一个模板?
@@ -95,6 +107,7 @@ async def create_async(
95107 template = await cls .get_template_async (template_name , config = config )
96108
97109 # 根据 template 类型创建相应的 Sandbox 子类
110+ from agentrun .sandbox .aio_sandbox import AioSandbox
98111 from agentrun .sandbox .browser_sandbox import BrowserSandbox
99112 from agentrun .sandbox .code_interpreter_sandbox import (
100113 CodeInterpreterSandbox ,
@@ -122,6 +135,10 @@ async def create_async(
122135 sandbox = BrowserSandbox .model_validate (
123136 base_sandbox .model_dump (by_alias = False )
124137 )
138+ elif template .template_type == TemplateType .AIO :
139+ sandbox = AioSandbox .model_validate (
140+ base_sandbox .model_dump (by_alias = False )
141+ )
125142 else :
126143 raise ValueError (
127144 f"template_type { template .template_type } is not supported"
@@ -198,14 +215,24 @@ async def connect_async(
198215 ) -> "BrowserSandbox" :
199216 ...
200217
218+ @classmethod
219+ @overload
220+ async def connect_async (
221+ cls ,
222+ sandbox_id : str ,
223+ template_type : Literal [TemplateType .AIO ],
224+ config : Optional [Config ] = None ,
225+ ) -> "AioSandbox" :
226+ ...
227+
201228 @classmethod
202229 @overload
203230 async def connect_async (
204231 cls ,
205232 sandbox_id : str ,
206233 template_type : None = None ,
207234 config : Optional [Config ] = None ,
208- ) -> Union ["CodeInterpreterSandbox" , "BrowserSandbox" ]:
235+ ) -> Union ["CodeInterpreterSandbox" , "BrowserSandbox" , "AioSandbox" ]:
209236 ...
210237
211238 @classmethod
@@ -214,7 +241,7 @@ async def connect_async(
214241 sandbox_id : str ,
215242 template_type : Optional [TemplateType ] = None ,
216243 config : Optional [Config ] = None ,
217- ) -> Union ["CodeInterpreterSandbox" , "BrowserSandbox" ]:
244+ ) -> Union ["CodeInterpreterSandbox" , "BrowserSandbox" , "AioSandbox" ]:
218245 """连接一个SandBox(异步)
219246
220247 Args:
@@ -255,6 +282,7 @@ async def connect_async(
255282 )
256283
257284 # 根据 template 类型创建相应的 Sandbox 子类
285+ from agentrun .sandbox .aio_sandbox import AioSandbox
258286 from agentrun .sandbox .browser_sandbox import BrowserSandbox
259287 from agentrun .sandbox .code_interpreter_sandbox import (
260288 CodeInterpreterSandbox ,
@@ -269,10 +297,14 @@ async def connect_async(
269297 result = BrowserSandbox .model_validate (
270298 sandbox .model_dump (by_alias = False )
271299 )
300+ elif template .template_type == TemplateType .AIO :
301+ result = AioSandbox .model_validate (
302+ sandbox .model_dump (by_alias = False )
303+ )
272304 else :
273305 raise ValueError (
274306 f"Unsupported template type: { template .template_type } . "
275- "Expected 'code-interpreter' or 'browser '"
307+ "Expected 'code-interpreter', 'browser' or 'aio '"
276308 )
277309
278310 result ._config = config
0 commit comments