AS AgentScopeAPI 手册 / API Reference

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
sandboxManagerSandboxManager沙箱管理器(类型 `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.

返回Returns SandboxManager
返回SandboxManager。Returns sandbox manager.
源码Source io/agentscope/runtime/engine/services/sandbox/SandboxService.java:57–59

start

public void start()

执行启动相关操作。

Returns the start.

源码Source io/agentscope/runtime/engine/services/sandbox/SandboxService.java:61–67

stop

public void stop()

执行停止相关操作。

Returns the stop.

源码Source io/agentscope/runtime/engine/services/sandbox/SandboxService.java:69–76

health

public boolean health()

返回健康状态。

Returns the health.

返回Returns boolean
返回布尔值,表示判断结果。Returns a boolean result.
源码Source io/agentscope/runtime/engine/services/sandbox/SandboxService.java:78–81

connect

public Sandbox connect(String sessionId, String userId, Class<? extends Sandbox> sandboxType)

用于会话的连接到沙箱环境。

Connect to sandbox environment for a session.

参数Parameters
名称Name类型Type说明Description
sessionIdString会话标识。The session ID
userIdString用户标识(类型 `String`)。Optional user ID
sandboxTypeClass<? extends Sandbox>沙箱类型(类型 `Class`)。sandbox type to connect to
返回Returns Sandbox
返回沙箱。List of sandbox instances
源码Source io/agentscope/runtime/engine/services/sandbox/SandboxService.java:91–104

connect

public Sandbox connect(String sessionId, String userId, Class<? extends Sandbox> sandboxType, String imageId)

建立连接并完成初始化。

Performs the connect operation.

参数Parameters
名称Name类型Type说明Description
sessionIdString会话标识(类型 `String`)。The session id.
userIdString用户标识(类型 `String`)。The user id.
sandboxTypeClass<? extends Sandbox>沙箱类型(类型 `Class`)。The sandbox type.
imageIdString图像标识(类型 `String`)。The image id.
返回Returns Sandbox
返回沙箱。Returns sandbox.
源码Source io/agentscope/runtime/engine/services/sandbox/SandboxService.java:106–129

connect

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
sessionIdString会话标识(类型 `String`)。The session id.
userIdString用户标识(类型 `String`)。The user id.
sandboxTypeClass<? extends Sandbox>沙箱类型(类型 `Class`)。The sandbox type.
imageIdString图像标识(类型 `String`)。The image id.
labelsMap<String, String>labels(类型 `Map`)。The labels.
返回Returns Sandbox
返回沙箱。Returns sandbox.
源码Source io/agentscope/runtime/engine/services/sandbox/SandboxService.java:131–156
基于官方固定版本源码静态生成Generated from pinned official sources · Python 2.0.11 · Java 2.0.4
签名与文档为静态抽取;如有疑问请以源码为准。Signatures and docs are extracted statically; verify against the source when in doubt.