Skip to content

Commit f2ea73b

Browse files
committed
feat(sandbox): add NAS, OSS, and PolarFS configuration support with multi-language docs
This commit introduces comprehensive storage configuration capabilities for sandbox environments, including NAS mount configurations, OSS mount points, and PolarFS filesystem support. The changes span across multiple files to enhance the sandbox creation API with new configuration options and improve documentation with bilingual comments. The modifications include: - Adding new model classes for NAS, OSS, and PolarFS configurations - Extending sandbox creation methods with optional storage parameters - Enhancing API endpoints to support new configuration options - Adding bilingual documentation (Chinese/English) for improved usability - Updating template files to reflect the new configuration parameters New features include the ability to specify NAS mount points with TLS encryption, OSS bucket mount points with read-only options, and PolarFS filesystem configurations during sandbox creation. Additionally, the commit includes workflow documentation for adding parameters to specific modules. 此提交为沙箱环境引入了全面的存储配置功能,包括 NAS 挂载配置、OSS 挂载点和 PolarFS 文件系统支持。这些更改跨越多个文件,以使用新的配置选项增强沙箱创建 API,并使用双语注释改进文档。 修改包括: - 为 NAS、OSS 和 PolarFS 配置添加新的模型类 - 使用可选存储参数扩展沙箱创建方法 - 增强 API 端点以支持新配置选项 - 添加双语文档(中文/英文)以提高可用性 - 更新模板文件以反映新的配置参数 新功能包括在沙箱创建期间指定具有 TLS 加密的 NAS 挂载点、具有只读选项的 OSS 存储桶挂载点以及 PolarFS 文件系统配置的能力。此外,提交还包括为特定模块添加参数的工作流程文档。 Change-Id: I2c16129da2d4c21ccf4f495c0c6fe62737af933c Signed-off-by: OhYee <[email protected]>
1 parent 6ae8e64 commit f2ea73b

File tree

10 files changed

+485
-118
lines changed

10 files changed

+485
-118
lines changed

AGENTS.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -447,3 +447,27 @@ A: 建议:
447447
- [Python SDK 文档](./python/README.md)
448448
- [示例代码](./python/examples/)
449449
- [阿里云 AgentRun 官方文档](https://help.aliyun.com/zh/agentrun/)
450+
451+
## 工作流程
452+
453+
### 为特定模块增加参数
454+
455+
名词解释
456+
- AgentRun SDK:当前项目
457+
- 底层 SDK:我们会依赖底层 SDK 与平台进行交互,如果是 python sdk,则为 `agentrun-20250910`;如果是 nodejs sdk,则为 `@alicloud/agentrun20250910`
458+
- 要修改模块:sandbox、model 等
459+
460+
此时,应该遵循如下流程
461+
462+
该模块的代码位于 ${component} 目录,包含如下部分
463+
- api/ 和底层 SDK 交互的逻辑。你可以根据该文件的调用方式,跳转到底层 sdk 的逻辑,进行检查
464+
- client 为用户封装的客户端,你需要检查一下是否需要修改
465+
- model 相关类型描述,你需要严格检查当前文件是否需要修改,这里可能存在大量修改
466+
- 其他文件 你也需要一并检查,如果是 nodejs sdk,需要检查 class 的属性
467+
- _xxx_async_template.py python sdk 中生成 xxx.py 文件的模板,只需要声明 async 即可(使用 `make codegen` 进行生成)
468+
469+
1. 请严格检查底层 SDK 的输入、输出参数,并对照现有类型定义,整理出新增的参数列表
470+
2. 根据新增的参数列表,在 agentrun sdk 中进行修改,补充对应的中英文注释
471+
3. 执行相关模块的 ut 测试,确保可以正确执行
472+
4. 进行修改内容的总结汇报
473+
5. 根据汇报内容进行检查,重新检查底层 SDK 和 AgentRun SDK 的定义

agentrun/sandbox/__client_async_template.py

Lines changed: 64 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"""
66

77
import time
8-
from typing import List, Optional, TYPE_CHECKING
8+
from typing import Any, Dict, List, Optional, TYPE_CHECKING
99

1010
from alibabacloud_agentrun20250910.models import (
1111
CreateTemplateInput,
@@ -18,7 +18,11 @@
1818
from agentrun.sandbox.model import (
1919
ListSandboxesInput,
2020
ListSandboxesOutput,
21+
NASConfig,
22+
OSSMountConfig,
2123
PageableInput,
24+
PolarFsConfig,
25+
SandboxInput,
2226
TemplateInput,
2327
)
2428
from agentrun.utils.config import Config
@@ -273,25 +277,50 @@ async def create_sandbox_async(
273277
self,
274278
template_name: str,
275279
sandbox_idle_timeout_seconds: Optional[int] = 600,
280+
sandbox_id: Optional[str] = None,
281+
nas_config: Optional[NASConfig] = None,
282+
oss_mount_config: Optional[OSSMountConfig] = None,
283+
polar_fs_config: Optional[PolarFsConfig] = None,
276284
config: Optional[Config] = None,
277285
) -> Sandbox:
278-
"""创建 Sandbox(异步)
286+
"""创建 Sandbox(异步) / Create Sandbox (async)
279287
280288
Args:
281-
input: Sandbox 配置
282-
config: 配置对象
289+
template_name: 模板名称 / Template name
290+
sandbox_idle_timeout_seconds: 沙箱空闲超时时间(秒) / Sandbox idle timeout (seconds)
291+
sandbox_id: 沙箱 ID(可选) / Sandbox ID (optional)
292+
nas_config: NAS 配置 / NAS configuration
293+
oss_mount_config: OSS 挂载配置 / OSS mount configuration
294+
polar_fs_config: PolarFS 配置 / PolarFS configuration
295+
config: 配置对象 / Config object
283296
284297
Returns:
285-
Sandbox: 创建的 Sandbox 对象
298+
Sandbox: 创建的 Sandbox 对象 / Created Sandbox object
286299
287300
Raises:
288-
ClientError: 客户端错误
289-
ServerError: 服务器错误
301+
ClientError: 客户端错误 / Client error
302+
ServerError: 服务器错误 / Server error
290303
"""
304+
# 将配置对象转换为字典格式
305+
nas_config_dict: Optional[Dict[str, Any]] = None
306+
if nas_config is not None:
307+
nas_config_dict = nas_config.model_dump(by_alias=True)
308+
309+
oss_mount_config_dict: Optional[Dict[str, Any]] = None
310+
if oss_mount_config is not None:
311+
oss_mount_config_dict = oss_mount_config.model_dump(by_alias=True)
312+
313+
polar_fs_config_dict: Optional[Dict[str, Any]] = None
314+
if polar_fs_config is not None:
315+
polar_fs_config_dict = polar_fs_config.model_dump(by_alias=True)
291316

292317
result = await self.__sandbox_data_api.create_sandbox_async(
293318
template_name=template_name,
294319
sandbox_idle_timeout_seconds=sandbox_idle_timeout_seconds,
320+
sandbox_id=sandbox_id,
321+
nas_config=nas_config_dict,
322+
oss_mount_config=oss_mount_config_dict,
323+
polar_fs_config=polar_fs_config_dict,
295324
config=config,
296325
)
297326

@@ -309,6 +338,34 @@ async def create_sandbox_async(
309338
data = result.get("data", {})
310339
return Sandbox.model_validate(data, by_alias=True)
311340

341+
async def create_sandbox_with_input_async(
342+
self,
343+
input: SandboxInput,
344+
config: Optional[Config] = None,
345+
) -> Sandbox:
346+
"""使用 SandboxInput 创建 Sandbox(异步) / Create Sandbox with SandboxInput (async)
347+
348+
Args:
349+
input: Sandbox 创建配置 / Sandbox creation configuration
350+
config: 配置对象 / Config object
351+
352+
Returns:
353+
Sandbox: 创建的 Sandbox 对象 / Created Sandbox object
354+
355+
Raises:
356+
ClientError: 客户端错误 / Client error
357+
ServerError: 服务器错误 / Server error
358+
"""
359+
return await self.create_sandbox_async(
360+
template_name=input.template_name,
361+
sandbox_idle_timeout_seconds=input.sandbox_idle_timeout_seconds,
362+
sandbox_id=input.sandbox_id,
363+
nas_config=input.nas_config,
364+
oss_mount_config=input.oss_mount_config,
365+
polar_fs_config=input.polar_fs_config,
366+
config=config,
367+
)
368+
312369
async def stop_sandbox_async(
313370
self, sandbox_id: str, config: Optional[Config] = None
314371
) -> Sandbox:

agentrun/sandbox/__sandbox_async_template.py

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,16 @@
44
This module defines the high-level API for sandbox resources.
55
"""
66

7-
from typing import List, Literal, Optional, overload, TYPE_CHECKING, Union
7+
from typing import (
8+
Any,
9+
Dict,
10+
List,
11+
Literal,
12+
Optional,
13+
overload,
14+
TYPE_CHECKING,
15+
Union,
16+
)
817

918
from agentrun.sandbox.model import TemplateType
1019
from agentrun.utils.config import Config
@@ -32,23 +41,29 @@ class Sandbox(BaseModel):
3241
_template_type: Optional[TemplateType]
3342

3443
created_at: Optional[str] = None
35-
"""沙箱创建时间"""
44+
"""沙箱创建时间 / Sandbox creation time"""
45+
ended_at: Optional[str] = None
46+
"""沙箱结束时间 / Sandbox end time"""
3647
last_updated_at: Optional[str] = None
37-
"""最后更新时间"""
48+
"""最后更新时间 / Last updated time"""
49+
metadata: Optional[Dict[str, Any]] = None
50+
"""元数据 / Metadata"""
3851
sandbox_arn: Optional[str] = None
39-
"""沙箱全局唯一资源名称"""
52+
"""沙箱全局唯一资源名称 / Sandbox ARN"""
4053
sandbox_id: Optional[str] = None
41-
"""沙箱 ID"""
54+
"""沙箱 ID / Sandbox ID"""
55+
sandbox_idle_ttlin_seconds: Optional[int] = None
56+
"""沙箱空闲 TTL(秒) / Sandbox Idle TTL (seconds)"""
4257
sandbox_idle_timeout_seconds: Optional[int] = None
43-
"""沙箱空闲超时时间(秒)"""
58+
"""沙箱空闲超时时间(秒) / Sandbox Idle Timeout (seconds)"""
4459
status: Optional[str] = None
45-
"""沙箱状态"""
60+
"""沙箱状态 / Sandbox status"""
4661
template_id: Optional[str] = None
47-
"""模板 ID"""
62+
"""模板 ID / Template ID"""
4863
template_name: Optional[str] = None
49-
"""模板名称"""
64+
"""模板名称 / Template name"""
5065
_config: Optional[Config] = None
51-
"""配置对象,用于子类的 data_api 初始化"""
66+
"""配置对象,用于子类的 data_api 初始化 / Config object for data_api initialization"""
5267

5368
@classmethod
5469
def __get_client(cls):

agentrun/sandbox/__template_async_template.py

Lines changed: 29 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -29,59 +29,61 @@ class Template(BaseModel):
2929
"""
3030

3131
template_id: Optional[str] = None
32-
"""模板 ID"""
32+
"""模板 ID / Template ID"""
3333
template_name: Optional[str] = None
34-
"""模板名称"""
34+
"""模板名称 / Template Name"""
3535
template_version: Optional[str] = None
36-
"""模板版本"""
36+
"""模板版本 / Template Version"""
3737
template_arn: Optional[str] = None
38-
"""模板 ARN"""
38+
"""模板 ARN / Template ARN"""
3939
resource_name: Optional[str] = None
40-
"""资源名称"""
40+
"""资源名称 / Resource Name"""
4141
template_type: Optional[TemplateType] = None
42-
"""模板类型"""
42+
"""模板类型 / Template Type"""
4343
cpu: Optional[float] = None
44-
"""CPU 核数"""
44+
"""CPU 核数 / CPU Cores"""
4545
memory: Optional[int] = None
46-
"""内存大小(MB)"""
46+
"""内存大小(MB) / Memory Size (MB)"""
4747
disk_size: Optional[int] = None
48-
"""磁盘大小(GB)"""
48+
"""磁盘大小(GB) / Disk Size (GB)"""
4949
description: Optional[str] = None
50-
"""描述"""
50+
"""描述 / Description"""
5151
execution_role_arn: Optional[str] = None
52-
"""执行角色 ARN"""
52+
"""执行角色 ARN / Execution Role ARN"""
5353
sandbox_idle_timeout_in_seconds: Optional[int] = None
54-
"""沙箱空闲超时时间(秒)"""
54+
"""沙箱空闲超时时间(秒) / Sandbox Idle Timeout (seconds)"""
5555
sandbox_ttlin_seconds: Optional[int] = None
56-
"""沙箱存活时间(秒)"""
56+
"""沙箱存活时间(秒) / Sandbox TTL (seconds)"""
5757
share_concurrency_limit_per_sandbox: Optional[int] = None
58-
"""每个沙箱的最大并发会话数"""
58+
"""每个沙箱的最大并发会话数 / Max Concurrency Limit Per Sandbox"""
5959
template_configuration: Optional[Dict] = None
60-
"""模板配置"""
60+
"""模板配置 / Template Configuration"""
6161
environment_variables: Optional[Dict] = None
62-
"""环境变量"""
62+
"""环境变量 / Environment Variables"""
6363
network_configuration: Optional[TemplateNetworkConfiguration] = None
64-
"""网络配置"""
64+
"""网络配置 / Network Configuration"""
6565
oss_configuration: Optional[List[TemplateOssConfiguration]] = None
66-
"""OSS 配置列表"""
66+
"""OSS 配置列表 / OSS Configuration List"""
6767
log_configuration: Optional[TemplateLogConfiguration] = None
68-
"""日志配置"""
68+
"""日志配置 / Log Configuration"""
6969
credential_configuration: Optional[TemplateCredentialConfiguration] = None
70-
"""凭证配置"""
70+
"""凭证配置 / Credential Configuration"""
7171
container_configuration: Optional[TemplateContainerConfiguration] = None
72-
"""容器配置"""
72+
"""容器配置 / Container Configuration"""
7373
mcp_options: Optional[TemplateMcpOptions] = None
74-
"""MCP 选项"""
74+
"""MCP 选项 / MCP Options"""
7575
mcp_state: Optional[TemplateMcpState] = None
76-
"""MCP 状态"""
76+
"""MCP 状态 / MCP State"""
77+
allow_anonymous_manage: Optional[bool] = None
78+
"""是否允许匿名管理 / Whether to allow anonymous management"""
7779
created_at: Optional[str] = None
78-
"""创建时间"""
80+
"""创建时间 / Creation Time"""
7981
last_updated_at: Optional[str] = None
80-
"""最后更新时间"""
82+
"""最后更新时间 / Last Updated Time"""
8183
status: Optional[str] = None
82-
"""状态"""
84+
"""状态 / Status"""
8385
status_reason: Optional[str] = None
84-
"""状态原因"""
86+
"""状态原因 / Status Reason"""
8587

8688
@classmethod
8789
def __get_client(cls, config: Optional[Config] = None):

agentrun/sandbox/api/__sandbox_data_async_template.py

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
This template is used to generate sandbox data API code.
55
"""
66

7-
from typing import Optional
7+
from typing import Any, Dict, Optional
88

99
from agentrun.utils.config import Config
1010
from agentrun.utils.data_api import DataAPI, ResourceType
@@ -70,16 +70,26 @@ async def create_sandbox_async(
7070
self,
7171
template_name: str,
7272
sandbox_idle_timeout_seconds: Optional[int] = 600,
73+
sandbox_id: Optional[str] = None,
74+
nas_config: Optional[Dict[str, Any]] = None,
75+
oss_mount_config: Optional[Dict[str, Any]] = None,
76+
polar_fs_config: Optional[Dict[str, Any]] = None,
7377
config: Optional[Config] = None,
7478
):
7579
self.__refresh_access_token(template_name=template_name, config=config)
76-
return await self.post_async(
77-
"/",
78-
data={
79-
"templateName": template_name,
80-
"sandboxIdleTimeoutSeconds": sandbox_idle_timeout_seconds,
81-
},
82-
)
80+
data: Dict[str, Any] = {
81+
"templateName": template_name,
82+
"sandboxIdleTimeoutSeconds": sandbox_idle_timeout_seconds,
83+
}
84+
if sandbox_id is not None:
85+
data["sandboxId"] = sandbox_id
86+
if nas_config is not None:
87+
data["nasConfig"] = nas_config
88+
if oss_mount_config is not None:
89+
data["ossMountConfig"] = oss_mount_config
90+
if polar_fs_config is not None:
91+
data["polarFsConfig"] = polar_fs_config
92+
return await self.post_async("/", data=data)
8393

8494
async def delete_sandbox_async(
8595
self, sandbox_id: str, config: Optional[Config] = None

0 commit comments

Comments
 (0)