SandboxService
public class SandboxService extends ServiceWithLifecycleManager
源码Source
io/agentscope/runtime/engine/services/sandbox/SandboxService.java:47–158沙箱服务,承载智能体的部署、调度与服务化运行。位于 io.agentscope.runtime.engine.services.sandbox 包,继承自 ServiceWithLifecycleManager。核心成员包括 getManagerApi、start、stop、health、connect、SandboxService。
Service for managing sandbox environments.
This service provides functionality to connect to sandbox environments, create new environments, and release them. It manages the lifecycle of sandbox instances associated with user sessions.
Usage Example:
`SandboxService sandboxService = new SandboxService("http://localhost:8000", "token");
sandboxService.start();
// Connect to sandbox for a session
Sandbox sandbox = sandboxService.connect("session_123", "user_456", BaseSandbox.class);
// Release sandbox
sandboxService.release("session_123", "user_456");
`
构造器摘要Constructor Summary
| 构造器Constructor | 说明Description |
|---|---|
public SandboxService(SandboxManager sandboxManager) | 初始化 `SandboxService` 实例。 Creates a new instance. |
方法摘要Method Summary
| 方法Method | 说明Description |
|---|---|
public SandboxManager getManagerApi() | 获取管理器 API。 Returns the manager api. |
public void start() | 执行启动相关操作。 Returns the start. |
public void stop() | 执行停止相关操作。 Returns the stop. |
public boolean health() | 返回健康状态。 Returns the health. |
public Sandbox connect(String sessionId, String userId, Class<? extends Sandbox> sandboxType) | 用于会话的连接到沙箱环境。 Connect to sandbox environment for a session. |
public Sandbox connect(String sessionId, String userId, Class<? extends Sandbox> sandboxType, String imageId) | 建立连接并完成初始化。 Performs the connect operation. |
public Sandbox connect(String sessionId, String userId, Class<? extends Sandbox> sandboxType, String imageId, Map<String, String> labels) | 建立连接并完成初始化。 Performs the connect operation. |
构造器详情Constructor Detail
SandboxService
public SandboxService(SandboxManager sandboxManager)
初始化 SandboxService 实例。
Creates a new instance.
参数Parameters
| 名称Name | 类型Type | 说明Description |
|---|---|---|
sandboxManager | SandboxManager | 沙箱管理器(类型 `SandboxManager`)。The sandbox manager. |
源码Source
io/agentscope/runtime/engine/services/sandbox/SandboxService.java:53–55方法详情Method Detail
getManagerApi
public SandboxManager getManagerApi()
获取管理器 API。
Returns the manager api.
SandboxManager返回SandboxManager。Returns sandbox manager.
源码Source
io/agentscope/runtime/engine/services/sandbox/SandboxService.java:57–59start
public void start()
执行启动相关操作。
Returns the start.
源码Source
io/agentscope/runtime/engine/services/sandbox/SandboxService.java:61–67stop
public void stop()
执行停止相关操作。
Returns the stop.
源码Source
io/agentscope/runtime/engine/services/sandbox/SandboxService.java:69–76health
public boolean health()
返回健康状态。
Returns the health.
boolean返回布尔值,表示判断结果。Returns a boolean result.
源码Source
io/agentscope/runtime/engine/services/sandbox/SandboxService.java:78–81connect
public Sandbox connect(String sessionId, String userId, Class<? extends Sandbox> sandboxType)
用于会话的连接到沙箱环境。
Connect to sandbox environment for a session.
参数Parameters
| 名称Name | 类型Type | 说明Description |
|---|---|---|
sessionId | String | 会话标识。The session ID |
userId | String | 用户标识(类型 `String`)。Optional user ID |
sandboxType | Class<? extends Sandbox> | 沙箱类型(类型 `Class`)。sandbox type to connect to |
Sandbox返回沙箱。List of sandbox instances
源码Source
io/agentscope/runtime/engine/services/sandbox/SandboxService.java:91–104connect
public Sandbox connect(String sessionId, String userId, Class<? extends Sandbox> sandboxType, String imageId)
建立连接并完成初始化。
Performs the connect operation.
参数Parameters
| 名称Name | 类型Type | 说明Description |
|---|---|---|
sessionId | String | 会话标识(类型 `String`)。The session id. |
userId | String | 用户标识(类型 `String`)。The user id. |
sandboxType | Class<? extends Sandbox> | 沙箱类型(类型 `Class`)。The sandbox type. |
imageId | String | 图像标识(类型 `String`)。The image id. |
Sandbox返回沙箱。Returns sandbox.
源码Source
io/agentscope/runtime/engine/services/sandbox/SandboxService.java:106–129connect
public Sandbox connect(String sessionId, String userId, Class<? extends Sandbox> sandboxType, String imageId, Map<String, String> labels)
建立连接并完成初始化。
Performs the connect operation.
参数Parameters
| 名称Name | 类型Type | 说明Description |
|---|---|---|
sessionId | String | 会话标识(类型 `String`)。The session id. |
userId | String | 用户标识(类型 `String`)。The user id. |
sandboxType | Class<? extends Sandbox> | 沙箱类型(类型 `Class`)。The sandbox type. |
imageId | String | 图像标识(类型 `String`)。The image id. |
labels | Map<String, String> | labels(类型 `Map`)。The labels. |
Sandbox返回沙箱。Returns sandbox.
源码Source
io/agentscope/runtime/engine/services/sandbox/SandboxService.java:131–156