AS AgentScopeAPI 手册 / API Reference

KubernetesSandbox

public class KubernetesSandbox extends AbstractBaseSandbox implements SandboxFileTransfer
源码Source io/agentscope/extensions/sandbox/kubernetes/KubernetesSandbox.java:48–354

Kubernetes 沙箱,在隔离环境中安全执行代码和工具。位于 io.agentscope.extensions.sandbox.kubernetes 包,继承自 AbstractBaseSandbox,实现 SandboxFileTransfer。核心成员包括 shutdown、doExec、doPersistWorkspace、doHydrateWorkspace、doSetupWorkspace、doDestroyWorkspace。

Harness io.agentscope.harness.agent.sandbox.Sandbox backed by an agent-sandbox CRD via the Java client SDK.

Assumes the runtime image conforms to the AgentScope runtime contract (see the sandbox documentation): POST /execute interprets the command with a POSIX shell, and the file API (/upload / /download) is rooted at a known base directory.

Workspace archives (persist / hydrate) are transferred through the runtime file API (files().read() / files().write()) when fileApiBaseDir is configured; when it is blank, transfers fall back to base64 payloads over exec. Single-file transfers requested by the harness filesystem (SandboxFileTransfer) also go through the file API for paths under fileApiBaseDir.

构造器摘要Constructor Summary

构造器Constructor说明Description
public KubernetesSandbox(KubernetesSandboxState state, Sandbox sdkSandbox)
初始化 `KubernetesSandbox` 实例。
Creates a new instance.

方法摘要Method Summary

方法Method说明Description
public void shutdown() throws Exception
关闭资源并释放连接。
Releases resources and connections.
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 Sandbox getSdkSandbox()
获取 `getSdkSandbox`。
Returns the underlying SDK sandbox handle.
public boolean supportsFileTransfer(String absolutePath)
设置该参数。
Performs the supports file transfer operation.
public void uploadFile(String absolutePath, byte[] content) throws Exception
执行上传文件相关操作。
Performs the upload file operation.
public byte[] downloadFile(String absolutePath) throws Exception
设置下载文件。
Performs the download file operation.

构造器详情Constructor Detail

KubernetesSandbox

public KubernetesSandbox(KubernetesSandboxState state, Sandbox sdkSandbox)

初始化 KubernetesSandbox 实例。

Creates a new instance.

参数Parameters
名称Name类型Type说明Description
stateKubernetesSandboxState状态对象(类型 `KubernetesSandboxState`)。The state.
sdkSandboxSandboxsdk 沙箱(类型 `Sandbox`)。The sdk sandbox.
源码Source io/agentscope/extensions/sandbox/kubernetes/KubernetesSandbox.java:58–62

方法详情Method Detail

shutdown

public void shutdown() throws Exception

关闭资源并释放连接。

Releases resources and connections.

抛出Throws
  • Exception 可能抛出 `Exception`。Thrown when the operation cannot be completed.
源码Source io/agentscope/extensions/sandbox/kubernetes/KubernetesSandbox.java:64–86

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/extensions/sandbox/kubernetes/KubernetesSandbox.java:88–109

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/extensions/sandbox/kubernetes/KubernetesSandbox.java:111–127

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/extensions/sandbox/kubernetes/KubernetesSandbox.java:169–180

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/extensions/sandbox/kubernetes/KubernetesSandbox.java:232–235

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/extensions/sandbox/kubernetes/KubernetesSandbox.java:237–247

getWorkspaceRoot

protected String getWorkspaceRoot()

获取工作区根。

Returns the workspace root.

返回Returns String
返回字符串结果。Returns a string.
源码Source io/agentscope/extensions/sandbox/kubernetes/KubernetesSandbox.java:249–252

getSdkSandbox

public Sandbox getSdkSandbox()

获取 getSdkSandbox。

Returns the underlying SDK sandbox handle.

返回Returns Sandbox
返回沙箱。SDK sandbox
源码Source io/agentscope/extensions/sandbox/kubernetes/KubernetesSandbox.java:259–261

supportsFileTransfer

public boolean supportsFileTransfer(String absolutePath)

设置该参数。

Performs the supports file transfer operation.

参数Parameters
名称Name类型Type说明Description
absolutePathStringabsolute 路径(类型 `String`)。The absolute path.
返回Returns boolean
返回布尔值,表示判断结果。Returns a boolean result.
源码Source io/agentscope/extensions/sandbox/kubernetes/KubernetesSandbox.java:263–266

uploadFile

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

执行上传文件相关操作。

Performs the upload file operation.

参数Parameters
名称Name类型Type说明Description
absolutePathStringabsolute 路径(类型 `String`)。The absolute path.
contentbyte[]内容(类型 `byte[]`)。The content.
抛出Throws
  • Exception 可能抛出 `Exception`。Thrown when the operation cannot be completed.
源码Source io/agentscope/extensions/sandbox/kubernetes/KubernetesSandbox.java:268–285

downloadFile

public byte[] downloadFile(String absolutePath) throws Exception

设置下载文件。

Performs the download file operation.

参数Parameters
名称Name类型Type说明Description
absolutePathStringabsolute 路径(类型 `String`)。The absolute path.
返回Returns byte[]
返回byte[]。Returns byte.
抛出Throws
  • Exception 可能抛出 `Exception`。Thrown when the operation cannot be completed.
源码Source io/agentscope/extensions/sandbox/kubernetes/KubernetesSandbox.java:287–290

继承成员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.