AS AgentScopeAPI 手册 / API Reference

DockerSandbox

public class DockerSandbox extends AbstractBaseSandbox implements SandboxFileTransfer
源码Source io/agentscope/harness/agent/sandbox/impl/docker/DockerSandbox.java:74–775

Docker 沙箱,承载智能体的部署、调度与服务化运行。位于 io.agentscope.harness.agent.sandbox.impl.docker 包,继承自 AbstractBaseSandbox,实现 SandboxFileTransfer。核心成员包括 start、shutdown、doExec、doPersistWorkspace、doHydrateWorkspace、doSetupWorkspace。

Docker io.agentscope.harness.agent.sandbox.Sandbox that runs commands in a container.

Uses the docker CLI via ProcessBuilder; no docker-java library dependency is required. The Docker daemon must be accessible on the host.

Container Lifecycle

  • On #start(): the container is created and started if it does not exist; if the container exists but is stopped it is restarted; if it is already running the existing container is reused.

  • On #stop(): the workspace snapshot is persisted (if configured). The container keeps running.

  • On #shutdown(): the container is stopped and removed if self-managed.

Workspace Operations

  • Exec: docker exec -w <root> <containerId> sh -c <command>

  • PersistWorkspace: docker exec <containerId> tar -cf - -C <root> .

  • HydrateWorkspace: docker exec -i <containerId> tar -xf - -C <root>

  • UploadFile / DownloadFile (SandboxFileTransfer): a host temp file round-tripped through docker cp, so file bytes never pass through exec argv or the stdout capture cap. Scoped to the workspace subtree by lexical validation; uploads land with mode 0644, matching the archive-hydrate fallback. Symlinks inside the sandbox are not resolved — the isolation boundary is the container, not the subtree.

构造器摘要Constructor Summary

构造器Constructor说明Description
public DockerSandbox(DockerSandboxState state)
初始化 `DockerSandbox` 实例。
Creates a new instance.

方法摘要Method Summary

方法Method说明Description
public void start() throws Exception
执行启动相关操作。
Ensures the backing Docker container is running before executing the standard 4-branch workspace start logic.
public void shutdown() throws Exception
关闭资源并释放连接。
Stops and removes the Docker container if self-managed.
protected ExecResult doExec(RuntimeContext runtimeContext, String command, int timeoutSeconds) throws Exception
执行 `doExec` 回调。
Performs the do exec operation.
protected InputStream doPersistWorkspace() throws Exception
执行 `doPersistWorkspace` 回调。
Returns the do persist workspace.
protected void doHydrateWorkspace(InputStream archive) throws Exception
执行 `doHydrateWorkspace` 回调。
Performs the do hydrate workspace operation.
protected void doSetupWorkspace() throws Exception
执行 `doSetupWorkspace` 回调。
Returns the do setup workspace.
protected void doDestroyWorkspace() throws Exception
执行 `doDestroyWorkspace` 回调。
Returns the do destroy workspace.
protected String getWorkspaceRoot()
获取工作区根。
Returns the workspace root.
public boolean supportsFileTransfer(String path)
设置该参数。
Performs the supports file transfer operation.
public void uploadFile(String path, byte[] content) throws Exception
执行上传文件相关操作。
Performs the upload file operation.
public byte[] downloadFile(String path) throws Exception
设置下载文件。
Performs the download file operation.

构造器详情Constructor Detail

DockerSandbox

public DockerSandbox(DockerSandboxState state)

初始化 DockerSandbox 实例。

Creates a new instance.

参数Parameters
名称Name类型Type说明Description
stateDockerSandboxState状态对象(类型 `DockerSandboxState`)。The state.
源码Source io/agentscope/harness/agent/sandbox/impl/docker/DockerSandbox.java:85–88

方法详情Method Detail

start

public void start() throws Exception

执行启动相关操作。

Ensures the backing Docker container is running before executing the standard 4-branch workspace start logic.

抛出Throws
  • Exception 可能抛出 `Exception`。Thrown when the operation cannot be completed.
源码Source io/agentscope/harness/agent/sandbox/impl/docker/DockerSandbox.java:96–100

shutdown

public void shutdown() throws Exception

关闭资源并释放连接。

Stops and removes the Docker container if self-managed.

抛出Throws
  • Exception 可能抛出 `Exception`。Thrown when the operation cannot be completed.
源码Source io/agentscope/harness/agent/sandbox/impl/docker/DockerSandbox.java:107–142

doExec

protected ExecResult doExec(RuntimeContext runtimeContext, String command, int timeoutSeconds) throws Exception

执行 doExec 回调。

Performs the do exec operation.

参数Parameters
名称Name类型Type说明Description
runtimeContextRuntimeContext运行时上下文(类型 `RuntimeContext`)。The runtime context.
commandString命令(类型 `String`)。The command.
timeoutSecondsint超时秒(类型 `int`)。The timeout seconds.
返回Returns ExecResult
返回ExecResult。Returns exec result.
抛出Throws
  • Exception 可能抛出 `Exception`。Thrown when the operation cannot be completed.
源码Source io/agentscope/harness/agent/sandbox/impl/docker/DockerSandbox.java:144–200

doPersistWorkspace

protected InputStream doPersistWorkspace() throws Exception

执行 doPersistWorkspace 回调。

Returns the do persist workspace.

返回Returns InputStream
返回InputStream。Returns input stream.
抛出Throws
  • Exception 可能抛出 `Exception`。Thrown when the operation cannot be completed.
源码Source io/agentscope/harness/agent/sandbox/impl/docker/DockerSandbox.java:202–259

doHydrateWorkspace

protected void doHydrateWorkspace(InputStream archive) throws Exception

执行 doHydrateWorkspace 回调。

Performs the do hydrate workspace operation.

参数Parameters
名称Name类型Type说明Description
archiveInputStream归档(类型 `InputStream`)。The archive.
抛出Throws
  • Exception 可能抛出 `Exception`。Thrown when the operation cannot be completed.
源码Source io/agentscope/harness/agent/sandbox/impl/docker/DockerSandbox.java:261–333

doSetupWorkspace

protected void doSetupWorkspace() throws Exception

执行 doSetupWorkspace 回调。

Returns the do setup workspace.

抛出Throws
  • Exception 可能抛出 `Exception`。Thrown when the operation cannot be completed.
源码Source io/agentscope/harness/agent/sandbox/impl/docker/DockerSandbox.java:335–340

doDestroyWorkspace

protected void doDestroyWorkspace() throws Exception

执行 doDestroyWorkspace 回调。

Returns the do destroy workspace.

抛出Throws
  • Exception 可能抛出 `Exception`。Thrown when the operation cannot be completed.
源码Source io/agentscope/harness/agent/sandbox/impl/docker/DockerSandbox.java:342–357

getWorkspaceRoot

protected String getWorkspaceRoot()

获取工作区根。

Returns the workspace root.

返回Returns String
返回字符串结果。Returns a string.
源码Source io/agentscope/harness/agent/sandbox/impl/docker/DockerSandbox.java:359–362

supportsFileTransfer

public boolean supportsFileTransfer(String path)

设置该参数。

Performs the supports file transfer operation.

参数Parameters
名称Name类型Type说明Description
pathString路径(类型 `String`)。The path.
返回Returns boolean
返回布尔值,表示判断结果。Returns a boolean result.
源码Source io/agentscope/harness/agent/sandbox/impl/docker/DockerSandbox.java:364–372

uploadFile

public void uploadFile(String path, byte[] content) throws Exception

执行上传文件相关操作。

Performs the upload file operation.

参数Parameters
名称Name类型Type说明Description
pathString路径(类型 `String`)。The path.
contentbyte[]内容(类型 `byte[]`)。The content.
抛出Throws
  • Exception 可能抛出 `Exception`。Thrown when the operation cannot be completed.
源码Source io/agentscope/harness/agent/sandbox/impl/docker/DockerSandbox.java:374–397

downloadFile

public byte[] downloadFile(String path) throws Exception

设置下载文件。

Performs the download file operation.

参数Parameters
名称Name类型Type说明Description
pathString路径(类型 `String`)。The path.
返回Returns byte[]
返回byte[]。Returns byte.
抛出Throws
  • Exception 可能抛出 `Exception`。Thrown when the operation cannot be completed.
源码Source io/agentscope/harness/agent/sandbox/impl/docker/DockerSandbox.java:399–414

继承成员Inherited Members

基于官方固定版本源码静态生成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.