Skip to content

Commit f377b0d

Browse files
authored
Merge pull request #14 from Serverless-Devs/feat-all-in-one-sandbox
[feat] implement all in one sandbox
2 parents 4dbc916 + ce65557 commit f377b0d

16 files changed

+5542
-22
lines changed

agentrun/sandbox/README.md

Lines changed: 451 additions & 4 deletions
Large diffs are not rendered by default.

agentrun/sandbox/README_zh.md

Lines changed: 436 additions & 2 deletions
Large diffs are not rendered by default.

agentrun/sandbox/__aio_sandbox_async_template.py

Lines changed: 523 additions & 0 deletions
Large diffs are not rendered by default.

agentrun/sandbox/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
33
提供沙箱环境管理功能,包括 Sandbox 和 Template 的创建、管理和控制。"""
44

5+
from .aio_sandbox import AioSandbox
56
from .browser_sandbox import BrowserSandbox
67
from .client import SandboxClient
78
from .code_interpreter_sandbox import CodeInterpreterSandbox
@@ -21,6 +22,7 @@
2122
TemplateNetworkConfiguration,
2223
TemplateNetworkMode,
2324
TemplateOssConfiguration,
25+
TemplateOSSPermission,
2426
TemplateType,
2527
)
2628
from .sandbox import Sandbox
@@ -34,6 +36,7 @@
3436
"Template",
3537
"CodeInterpreterSandbox",
3638
"BrowserSandbox",
39+
"AioSandbox",
3740
# 模型类
3841
"SandboxInput",
3942
"TemplateInput",
@@ -51,4 +54,5 @@
5154
"ListSandboxesInput",
5255
"ListSandboxesOutput",
5356
"CodeLanguage",
57+
"TemplateOSSPermission",
5458
]

agentrun/sandbox/__sandbox_async_template.py

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from agentrun.utils.model import BaseModel
1212

1313
if 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

Comments
 (0)