AS AgentScopeAPI 手册 / API Reference

WorkspaceSandbox

public final class WorkspaceSandbox implements Sandbox
源码Source io/agentscope/builder/web/managed/WorkspaceSandbox.java:40–168

工作区沙箱,承载智能体的部署、调度与服务化运行。位于 io.agentscope.builder.web.managed 包,实现 Sandbox。核心成员包括 workDir、start、stop、shutdown、close、isRunning。

Docker-less Sandbox backed by a plain host directory, registered by an Environment Worker (via the worker REST API) as the Priority-1 externalSandbox for a self_hosted managed session.

The harness never calls #stop()/#shutdown() on a Priority-1 sandbox (see SandboxManager.release) — the registering worker owns the full lifecycle, including deleting #workDir() once the session is done with it. #start() is called once per turn by SandboxLifecycleMiddleware and is idempotent.

构造器摘要Constructor Summary

构造器Constructor说明Description
public WorkspaceSandbox(String sessionId, Path workDir)
初始化 `WorkspaceSandbox` 实例。
Creates a new instance.

方法摘要Method Summary

方法Method说明Description
public Path workDir()
返回 `workDir` 结果。
Host directory backing this sandbox's shell execution and (indirectly) its filesystem.
public void start() throws Exception
执行启动相关操作。
Returns the start.
public void stop() throws Exception
执行停止相关操作。
Returns the stop.
public void shutdown() throws Exception
关闭资源并释放连接。
Releases resources and connections.
public void close() throws Exception
关闭连接并释放相关资源。
Releases resources and connections.
public boolean isRunning()
判断是否运行中。
Returns whether the running.
public SandboxState getState()
获取状态。
Returns the state.
public ExecResult exec(RuntimeContext runtimeContext, String command, Integer timeoutSeconds) throws Exception
执行 `exec` 方法。
Performs the exec operation.
public InputStream persistWorkspace() throws Exception
返回 `persistWorkspace` 结果。
Returns the persist workspace.
public void hydrateWorkspace(InputStream archive) throws Exception
设置该参数。
Performs the hydrate workspace operation.

构造器详情Constructor Detail

WorkspaceSandbox

public WorkspaceSandbox(String sessionId, Path workDir)

初始化 WorkspaceSandbox 实例。

Creates a new instance.

参数Parameters
名称Name类型Type说明Description
sessionIdString会话标识(类型 `String`)。The session id.
workDirPathwork 目录(类型 `Path`)。The work dir.
源码Source io/agentscope/builder/web/managed/WorkspaceSandbox.java:49–53

方法详情Method Detail

workDir

public Path workDir()

返回 workDir 结果。

Host directory backing this sandbox's shell execution and (indirectly) its filesystem.

返回Returns Path
返回路径。Returns path.
源码Source io/agentscope/builder/web/managed/WorkspaceSandbox.java:56–58

start

public void start() throws Exception

执行启动相关操作。

Returns the start.

抛出Throws
  • Exception 可能抛出 `Exception`。Thrown when the operation cannot be completed.
源码Source io/agentscope/builder/web/managed/WorkspaceSandbox.java:60–64

stop

public void stop() throws Exception

执行停止相关操作。

Returns the stop.

抛出Throws
  • Exception 可能抛出 `Exception`。Thrown when the operation cannot be completed.
源码Source io/agentscope/builder/web/managed/WorkspaceSandbox.java:66–69

shutdown

public void shutdown() throws Exception

关闭资源并释放连接。

Releases resources and connections.

抛出Throws
  • Exception 可能抛出 `Exception`。Thrown when the operation cannot be completed.
源码Source io/agentscope/builder/web/managed/WorkspaceSandbox.java:71–74

close

public void close() throws Exception

关闭连接并释放相关资源。

Releases resources and connections.

抛出Throws
  • Exception 可能抛出 `Exception`。Thrown when the operation cannot be completed.
源码Source io/agentscope/builder/web/managed/WorkspaceSandbox.java:76–79

isRunning

public boolean isRunning()

判断是否运行中。

Returns whether the running.

返回Returns boolean
返回布尔值,表示判断结果。Returns a boolean result.
源码Source io/agentscope/builder/web/managed/WorkspaceSandbox.java:81–84

getState

public SandboxState getState()

获取状态。

Returns the state.

返回Returns SandboxState
返回SandboxState。Returns sandbox state.
源码Source io/agentscope/builder/web/managed/WorkspaceSandbox.java:86–89

exec

public ExecResult exec(RuntimeContext runtimeContext, String command, Integer timeoutSeconds) throws Exception

执行 exec 方法。

Performs the exec operation.

参数Parameters
名称Name类型Type说明Description
runtimeContextRuntimeContext运行时上下文(类型 `RuntimeContext`)。The runtime context.
commandString命令(类型 `String`)。The command.
timeoutSecondsInteger超时秒(类型 `Integer`)。The timeout seconds.
返回Returns ExecResult
返回ExecResult。Returns exec result.
抛出Throws
  • Exception 可能抛出 `Exception`。Thrown when the operation cannot be completed.
源码Source io/agentscope/builder/web/managed/WorkspaceSandbox.java:91–126

persistWorkspace

public InputStream persistWorkspace() throws Exception

返回 persistWorkspace 结果。

Returns the persist workspace.

返回Returns InputStream
返回InputStream。Returns input stream.
抛出Throws
  • Exception 可能抛出 `Exception`。Thrown when the operation cannot be completed.
源码Source io/agentscope/builder/web/managed/WorkspaceSandbox.java:152–157

hydrateWorkspace

public void hydrateWorkspace(InputStream archive) throws Exception

设置该参数。

Performs the hydrate workspace operation.

参数Parameters
名称Name类型Type说明Description
archiveInputStream归档(类型 `InputStream`)。The archive.
抛出Throws
  • Exception 可能抛出 `Exception`。Thrown when the operation cannot be completed.
源码Source io/agentscope/builder/web/managed/WorkspaceSandbox.java:159–164
基于官方固定版本源码静态生成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.