AS AgentScopeAPI 手册 / API Reference
类class agentscope.workspace

AppleContainerBackend

class AppleContainerBackend(BackendBase)
源码Source agentscope/workspace/_applecontainer/_applecontainer_backend.py:23–215

Apple 容器 Backend,在隔离环境中安全执行代码和工具。位于 agentscope.workspace 包,继承自 BackendBase。核心成员包括 getcwd、exec_shell、read_file、write_file。

Only the three abstract primitives (exec_shell, read_file, write_file) are implemented here; the derived filesystem helpers are inherited from :class:BackendBase.

构造器摘要Constructor Summary

构造器Constructor说明Description
def __init__(container_id: str, workdir: str) -> None
初始化 `AppleContainerBackend` 实例。
Initialize the Apple Container backend.

方法摘要Method Summary

方法Method说明Description
async def getcwd() -> strasync
返回 `getcwd` 结果。
Return the container's default working directory.
async def exec_shell(command: list[str], *, cwd: str | None = None, timeout: float | None = None) -> ExecResultasync
执行 `exec_shell` 方法。
Run a program inside the Apple container via ``container exec``.
async def read_file(path: str) -> bytesasync
设置读取文件。
Read a file from the container via ``container exec cat``.
async def write_file(path: str, data: bytes) -> Noneasync
执行写入文件相关操作。
Write *data* to a file inside the container via ``container cp``.

构造器详情Constructor Detail

AppleContainerBackend

def __init__(container_id: str, workdir: str) -> None

初始化 AppleContainerBackend 实例。

Initialize the Apple Container backend.

参数Parameters
名称Name类型Type说明Description
container_idstr容器标识(类型 `str`)。The container identifier.
workdirstrworkdir(类型 `str`)。Default working directory for `exec_shell` calls inside the container.
源码Source agentscope/workspace/_applecontainer/_applecontainer_backend.py:40–51

方法详情Method Detail

getcwd

async def getcwd() -> str
async

返回 getcwd 结果。

Return the container's default working directory.

返回Returns str
返回字符串结果。`str`:
源码Source agentscope/workspace/_applecontainer/_applecontainer_backend.py:55–62

exec_shell

async def exec_shell(command: list[str], *, cwd: str | None = None, timeout: float | None = None) -> ExecResult
async

执行 exec_shell 方法。

command* is an argv list passed directly after the container identifier — no -- separator is used (Apple Container treats -- as the target executable).

参数Parameters
名称Name类型Type说明Description
commandlist[str]命令(类型 `list[str]`)。Executable path/name followed by its arguments.
cwdkw默认default Nonestr | Nonecwd(类型 `str | None`)。Working directory inside the container. When `None` the backend's default `workdir` is used.
timeoutkw默认default Nonefloat | None超时时间(类型 `float | None`)。Maximum number of seconds to wait. When `None` the call waits indefinitely.
返回Returns ExecResult
返回ExecResult。`ExecResult`:
源码Source agentscope/workspace/_applecontainer/_applecontainer_backend.py:64–138

read_file

async def read_file(path: str) -> bytes
async

设置读取文件。

Read a file from the container via container exec cat.

参数Parameters
名称Name类型Type说明Description
pathstr路径(类型 `str`)。Path to the file inside the container.
返回Returns bytes
返回字节。`bytes`:
异常Raises
  • 可能抛出 `Exception`。`FileNotFoundError`:
  • 可能抛出 `Exception`。If the path does not exist inside the container.
源码Source agentscope/workspace/_applecontainer/_applecontainer_backend.py:142–163

write_file

async def write_file(path: str, data: bytes) -> None
async

执行写入文件相关操作。

Writes data to a host-side temp file, then copies it into the container.

参数Parameters
名称Name类型Type说明Description
pathstr路径(类型 `str`)。Destination path inside the container.
databytes原始字节到写入。The raw bytes to write.
返回Returns None
无返回值。No value is returned.
源码Source agentscope/workspace/_applecontainer/_applecontainer_backend.py:165–215

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