AbstractBaseSandbox
public abstract class AbstractBaseSandbox implements Sandbox
io/agentscope/harness/agent/sandbox/AbstractBaseSandbox.java:48–288抽象基类沙箱,承载智能体的部署、调度与服务化运行。位于 io.agentscope.harness.agent.sandbox 包,实现 Sandbox。核心成员包括 start、stop、close、isRunning、getState、exec。
Abstract base implementation of Sandbox with the 4-branch workspace start logic.
4-Branch Start Logic
Branch A: workspaceRootReady=true & workspace dir exists → apply ephemeral-only entries
Branch B: workspaceRootReady=true & workspace dir missing → restore from snapshot + ephemeral entries
Branch C: workspaceRootReady=false & snapshot is restorable → hydrate from snapshot + all entries
Branch D: workspaceRootReady=false & no restorable snapshot → fresh init from full workspace spec
Subclasses implement the backend-specific operations:
-
#doExec(RuntimeContext, String, int)— execute a shell command in the workspace -
#doPersistWorkspace()— create a tar archive of the workspace -
#doHydrateWorkspace(InputStream)— extract a tar archive into the workspace -
#doSetupWorkspace()— create the workspace root directory -
#doDestroyWorkspace()— delete the workspace root directory (on shutdown) -
#getWorkspaceRoot()— return the workspace root path string
构造器摘要Constructor Summary
| 构造器Constructor | 说明Description |
|---|---|
protected AbstractBaseSandbox(SandboxState state) | 初始化 `AbstractBaseSandbox` 实例。 Creates a new instance. |
方法摘要Method Summary
| 方法Method | 说明Description |
|---|---|
public void start() throws Exception | 执行启动相关操作。 Executes the 4-branch workspace start logic. |
public void stop() throws Exception | 执行停止相关操作。 Persists the workspace snapshot and marks the workspace root as ready. |
public void close() throws Exception | 关闭连接并释放相关资源。 {@inheritDoc} |
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` 方法。 Delegates to `#doExec(RuntimeContext, String, int)` with a fallback timeout. |
public InputStream persistWorkspace() throws Exception | 返回 `persistWorkspace` 结果。 Returns the persist workspace. |
public void hydrateWorkspace(InputStream archive) throws Exception | 设置该参数。 Performs the hydrate workspace operation. |
protected boolean probeWorkspaceRootForPreservedResume() | 返回 `probeWorkspaceRootForPreservedResume` 结果。 Probes whether the workspace root directory still exists, using a backend exec. |
protected int getDefaultExecTimeoutSeconds() | 返回默认命令执行超时 in 秒。 Returns the default command execution timeout in seconds. |
protected abstract ExecResult doExec(RuntimeContext runtimeContext, String command, int timeoutSeconds) throws Exceptionabstract | 执行 `doExec` 回调。 Executes a shell command within the workspace. |
protected abstract InputStream doPersistWorkspace() throws Exceptionabstract | 执行 `doPersistWorkspace` 回调。 Creates a tar archive of the current workspace contents. |
protected abstract void doHydrateWorkspace(InputStream archive) throws Exceptionabstract | 执行 `doHydrateWorkspace` 回调。 Extracts a tar archive into the workspace. |
protected abstract void doSetupWorkspace() throws Exceptionabstract | 创建工作区根目录。 Creates the workspace root directory. |
protected abstract void doDestroyWorkspace() throws Exceptionabstract | 执行 `doDestroyWorkspace` 回调。 Destroys the workspace root and any backend resources. |
protected abstract String getWorkspaceRoot()abstract | 获取工作区根。 Returns the absolute path of the workspace root directory. |
构造器详情Constructor Detail
AbstractBaseSandbox
protected AbstractBaseSandbox(SandboxState state)
初始化 AbstractBaseSandbox 实例。
Creates a new instance.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
state | SandboxState | 状态对象(类型 `SandboxState`)。The state. |
io/agentscope/harness/agent/sandbox/AbstractBaseSandbox.java:59–62方法详情Method Detail
start
public void start() throws Exception
执行启动相关操作。
Executes the 4-branch workspace start logic.
Exception可能抛出 `Exception`。Thrown when the operation cannot be completed.
io/agentscope/harness/agent/sandbox/AbstractBaseSandbox.java:69–124stop
public void stop() throws Exception
执行停止相关操作。
Persists the workspace snapshot and marks the workspace root as ready.
Exception可能抛出 `Exception`。Thrown when the operation cannot be completed.
io/agentscope/harness/agent/sandbox/AbstractBaseSandbox.java:131–141close
public void close() throws Exception
关闭连接并释放相关资源。
{@inheritDoc} Calls #stop() then #shutdown().
Exception可能抛出 `Exception`。Thrown when the operation cannot be completed.
io/agentscope/harness/agent/sandbox/AbstractBaseSandbox.java:149–157isRunning
public boolean isRunning()
判断是否运行中。
Returns whether the running.
booleanio/agentscope/harness/agent/sandbox/AbstractBaseSandbox.java:159–162getState
public SandboxState getState()
获取状态。
Returns the state.
SandboxStateio/agentscope/harness/agent/sandbox/AbstractBaseSandbox.java:164–167exec
public ExecResult exec(RuntimeContext runtimeContext, String command, Integer timeoutSeconds) throws Exception
执行 exec 方法。
Delegates to #doExec(RuntimeContext, String, int) with a fallback timeout.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
runtimeContext | RuntimeContext | 运行时上下文(类型 `RuntimeContext`)。The runtime context. |
command | String | 命令(类型 `String`)。The command. |
timeoutSeconds | Integer | 超时秒(类型 `Integer`)。The timeout seconds. |
ExecResultException可能抛出 `Exception`。Thrown when the operation cannot be completed.
io/agentscope/harness/agent/sandbox/AbstractBaseSandbox.java:172–177persistWorkspace
public InputStream persistWorkspace() throws Exception
返回 persistWorkspace 结果。
Returns the persist workspace.
InputStreamException可能抛出 `Exception`。Thrown when the operation cannot be completed.
io/agentscope/harness/agent/sandbox/AbstractBaseSandbox.java:179–182hydrateWorkspace
public void hydrateWorkspace(InputStream archive) throws Exception
设置该参数。
Performs the hydrate workspace operation.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
archive | InputStream | 归档(类型 `InputStream`)。The archive. |
Exception可能抛出 `Exception`。Thrown when the operation cannot be completed.
io/agentscope/harness/agent/sandbox/AbstractBaseSandbox.java:184–187probeWorkspaceRootForPreservedResume
protected boolean probeWorkspaceRootForPreservedResume()
返回 probeWorkspaceRootForPreservedResume 结果。
Probes whether the workspace root directory still exists, using a backend exec.
booleanio/agentscope/harness/agent/sandbox/AbstractBaseSandbox.java:197–207getDefaultExecTimeoutSeconds
protected int getDefaultExecTimeoutSeconds()
返回默认命令执行超时 in 秒。
Returns the default command execution timeout in seconds.
intio/agentscope/harness/agent/sandbox/AbstractBaseSandbox.java:214–216doExec
protected abstract ExecResult doExec(RuntimeContext runtimeContext, String command, int timeoutSeconds) throws Exception
执行 doExec 回调。
Executes a shell command within the workspace.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
runtimeContext | RuntimeContext | 运行时上下文(类型 `RuntimeContext`)。per-call context; may be `null` for internal probes |
command | String | 命令(类型 `String`)。shell command string |
timeoutSeconds | int | 超时秒(类型 `int`)。maximum execution time |
ExecResultException可能抛出 `Exception`。Thrown when the operation cannot be completed.
io/agentscope/harness/agent/sandbox/AbstractBaseSandbox.java:227–228doPersistWorkspace
protected abstract InputStream doPersistWorkspace() throws Exception
执行 doPersistWorkspace 回调。
Creates a tar archive of the current workspace contents.
InputStreamException可能抛出 `Exception`。Thrown when the operation cannot be completed.
io/agentscope/harness/agent/sandbox/AbstractBaseSandbox.java:236doHydrateWorkspace
protected abstract void doHydrateWorkspace(InputStream archive) throws Exception
执行 doHydrateWorkspace 回调。
Extracts a tar archive into the workspace.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
archive | InputStream | 归档(类型 `InputStream`)。the tar archive stream to extract |
Exception可能抛出 `Exception`。Thrown when the operation cannot be completed.
io/agentscope/harness/agent/sandbox/AbstractBaseSandbox.java:244doSetupWorkspace
protected abstract void doSetupWorkspace() throws Exception
创建工作区根目录。
Creates the workspace root directory.
Exception可能抛出 `Exception`。Thrown when the operation cannot be completed.
io/agentscope/harness/agent/sandbox/AbstractBaseSandbox.java:251doDestroyWorkspace
protected abstract void doDestroyWorkspace() throws Exception
执行 doDestroyWorkspace 回调。
Destroys the workspace root and any backend resources.
Exception可能抛出 `Exception`。Thrown when the operation cannot be completed.
io/agentscope/harness/agent/sandbox/AbstractBaseSandbox.java:258getWorkspaceRoot
protected abstract String getWorkspaceRoot()
获取工作区根。
Returns the absolute path of the workspace root directory.
Stringio/agentscope/harness/agent/sandbox/AbstractBaseSandbox.java:265