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

BubblewrapBackend

class BubblewrapBackend(BackendBase)
源码Source agentscope/workspace/_bubblewrap/_bubblewrap_backend.py:23–603

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

Backend that executes commands inside Bubblewrap sandboxes. Declared in agentscope.workspace. Extends BackendBase.

构造器摘要Constructor Summary

构造器Constructor说明Description
def __init__(*, host_workdir: str, host_tmpdir: str, host_cache_dir: str | None = None, workdir: str = SANDBOX_WORKDIR,…
初始化 `BubblewrapBackend` 实例。
Creates a new instance.

方法摘要Method Summary

方法Method说明Description
async def getcwd() -> strasync
返回 `getcwd` 结果。
Return the backend's default working directory.
async def exec_shell(command: list[str], *, cwd: str | None = None, timeout: float | None = None) -> ExecResultasync
执行 `exec_shell` 方法。
Run an argv list inside a fresh Bubblewrap process.
async def start_process(command: list[str], *, cwd: str | None = None, stdin: Any = asyncio.subprocess.DEVNULL, stdout:…async
启动 `start_process`。
Start a long-running command inside Bubblewrap.
async def read_file(path: str) -> bytesasync
设置读取文件。
Read a sandbox file as raw bytes.
async def write_file(path: str, data: bytes) -> Noneasync
执行写入文件相关操作。
Write raw bytes, refusing every symbolic-link final component.
async def write_stream(path: str, stream: AsyncIterator[bytes]) -> Noneasync
执行写入流相关操作。
Stream bytes into ``path``, chunk by chunk through ``cat``.

构造器详情Constructor Detail

BubblewrapBackend

def __init__(*, host_workdir: str, host_tmpdir: str, host_cache_dir: str | None = None, workdir: str = SANDBOX_WORKDIR, share_net: bool = True, env: dict[str, str] | None = None) -> None

初始化 BubblewrapBackend 实例。

Creates a new instance.

参数Parameters
名称Name类型Type说明Description
host_workdirkwstrhost workdir(类型 `str`)。The host workdir.
host_tmpdirkwstrhost tmpdir(类型 `str`)。The host tmpdir.
host_cache_dirkw默认default Nonestr | Nonehost 缓存目录(类型 `str | None`)。The host cache dir.
workdirkw默认default SANDBOX_WORKDIRstrworkdir(类型 `str`)。The workdir.
share_netkw默认default Trueboolshare net(类型 `bool`)。The share net.
envkw默认default Nonedict[str, str] | Noneenv(类型 `dict[str, str] | None`)。The env.
源码Source agentscope/workspace/_bubblewrap/_bubblewrap_backend.py:47–117

方法详情Method Detail

getcwd

async def getcwd() -> str
async

返回 getcwd 结果。

Return the backend's default working directory.

返回Returns str
返回字符串结果。Returns a string.
源码Source agentscope/workspace/_bubblewrap/_bubblewrap_backend.py:119–121

exec_shell

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

执行 exec_shell 方法。

Run an argv list inside a fresh Bubblewrap process.

参数Parameters
名称Name类型Type说明Description
commandlist[str]命令(类型 `list[str]`)。The command.
cwdkw默认default Nonestr | Nonecwd(类型 `str | None`)。The cwd.
timeoutkw默认default Nonefloat | None超时时间(类型 `float | None`)。The timeout.
返回Returns ExecResult
返回ExecResult。Returns exec result.
源码Source agentscope/workspace/_bubblewrap/_bubblewrap_backend.py:123–170

start_process

async def start_process(command: list[str], *, cwd: str | None = None, stdin: Any = asyncio.subprocess.DEVNULL, stdout: Any = asyncio.subprocess.DEVNULL, stderr: Any = asyncio.subprocess.DEVNULL) -> asyncio.subprocess.Process
async

启动 start_process。

Used by :class:BubblewrapWorkspace to keep the MCP gateway as a tracked subprocess instead of daemonizing it inside the sandbox.

参数Parameters
名称Name类型Type说明Description
commandlist[str]命令(类型 `list[str]`)。The command.
cwdkw默认default Nonestr | Nonecwd(类型 `str | None`)。The cwd.
stdinkw默认default asyncio.subprocess.DEVNULLAnystdin(类型 `Any`)。The stdin.
stdoutkw默认default asyncio.subprocess.DEVNULLAnystdout(类型 `Any`)。The stdout.
stderrkw默认default asyncio.subprocess.DEVNULLAnystderr(类型 `Any`)。The stderr.
返回Returns asyncio.subprocess.Process
返回asyncio.subprocess.Process。Returns asyncio subprocess process.
源码Source agentscope/workspace/_bubblewrap/_bubblewrap_backend.py:172–196

read_file

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

设置读取文件。

Files under /workspace and /tmp are read by a command running inside Bubblewrap.

参数Parameters
名称Name类型Type说明Description
pathstr路径(类型 `str`)。The path.
返回Returns bytes
返回字节。Returns bytes.
源码Source agentscope/workspace/_bubblewrap/_bubblewrap_backend.py:242–281

write_file

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

执行写入文件相关操作。

Write raw bytes, refusing every symbolic-link final component.

参数Parameters
名称Name类型Type说明Description
pathstr路径(类型 `str`)。The path.
databytes数据(类型 `bytes`)。The data.
返回Returns None
无返回值。No value is returned.
源码Source agentscope/workspace/_bubblewrap/_bubblewrap_backend.py:283–285

write_stream

async def write_stream(path: str, stream: AsyncIterator[bytes]) -> None
async

执行写入流相关操作。

Stream bytes into path, chunk by chunk through cat.

参数Parameters
名称Name类型Type说明Description
pathstr路径(类型 `str`)。The path.
streamAsyncIterator[bytes]流(类型 `AsyncIterator[bytes]`)。The stream.
返回Returns None
无返回值。No value is returned.
源码Source agentscope/workspace/_bubblewrap/_bubblewrap_backend.py:287–293

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