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

BubblewrapWorkspace

class BubblewrapWorkspace(SandboxedWorkspaceBase)
源码Source agentscope/workspace/_bubblewrap/_bubblewrap_workspace.py:52–658

Bubblewrap 工作区,在隔离环境中安全执行代码和工具。位于 agentscope.workspace 包,继承自 SandboxedWorkspaceBase。核心成员包括 initialize、get_instructions、is_persistent。

host_workdir is mounted read-write at /workspace. When it is omitted, an ephemeral temp directory is created and removed on close. Bootstrap caches are stored outside host_workdir by default, and the backend detects mount-source replacement before launching Bubblewrap. An explicit host_cache_dir must not overlap host_workdir or the backend's temporary directory; sharing one cache between mutually trusted workspaces is an opt-in tradeoff.

构造器摘要Constructor Summary

构造器Constructor说明Description
def __init__(*, workspace_id: str | None = None, host_workdir: str | None = None, host_cache_dir: str | None = None, ga…
初始化 `BubblewrapWorkspace` 实例。
Construct a :class:`BubblewrapWorkspace`.

属性摘要Property Summary

属性Property说明Description
is_persistent
读取 `is_persistent` 属性。
Whether the workspace files survive ``close``.

方法摘要Method Summary

方法Method说明Description
async def initialize() -> Noneasync
初始化 `BubblewrapWorkspace` 实例。
Initialize and clean up partial resources on failure.
async def get_instructions() -> strasync
获取指令。
Return the system-prompt fragment for this workspace.

构造器详情Constructor Detail

BubblewrapWorkspace

def __init__(*, workspace_id: str | None = None, host_workdir: str | None = None, host_cache_dir: str | None = None, gateway_port: int | None = DEFAULT_GATEWAY_PORT, share_net: bool = True, env: dict[str, str] | None = None, extra_pip: list[str] | None = None, instructions: str = _DEFAULT_INSTRUCTIONS, default_mcps: list[MCPClient] | None = None, skill_paths: list[str] | None = None) -> None

初始化 BubblewrapWorkspace 实例。

Construct a :class:BubblewrapWorkspace.

参数Parameters
名称Name类型Type说明Description
workspace_idkw默认default Nonestr | None工作区标识(类型 `str | None`)。Stable workspace identifier.
host_workdirkw默认default Nonestr | Nonehost workdir(类型 `str | None`)。Host directory mounted at `/workspace`. Omit for an ephemeral workspace.
host_cache_dirkw默认default Nonestr | Nonehost 缓存目录(类型 `str | None`)。Host directory mounted at `/tmp/.agentscope-cache` for package caches. Omit to use a workspace-private cache outside `host_workdir`. An explicit path must not overlap the workspace or its temporary directory. Supplying a shared directory weakens cross-workspace isolation and should only be used for mutually trusted workspaces.
gateway_portkw默认default DEFAULT_GATEWAY_PORTint | None网关 port(类型 `int | None`)。TCP port used by the in-sandbox gateway. `None` allocates an available loopback port during initialization.
share_netkw默认default Trueboolshare net(类型 `bool`)。Must be `True` for this workspace because the TCP MCP gateway is reached across separate `bwrap` executions.
envkw默认default Nonedict[str, str] | Noneenv(类型 `dict[str, str] | None`)。Extra environment variables for sandboxed commands.
extra_pipkw默认default Nonelist[str] | Noneextra pip(类型 `list[str] | None`)。Extra Python requirements installed into the gateway venv. For a persistent `host_workdir`, keep this list stable across workspace instances; changing it does not currently invalidate an existing Bootstrap environment.
instructionskw默认default _DEFAULT_INSTRUCTIONSstr指令(类型 `str`)。System-prompt fragment template.
default_mcpskw默认default Nonelist[MCPClient] | None默认 mcps(类型 `list[MCPClient] | None`)。MCPs seeded on first initialization.
skill_pathskw默认default Nonelist[str] | None技能 paths(类型 `list[str] | None`)。Local skill directories seeded on first initialization.
源码Source agentscope/workspace/_bubblewrap/_bubblewrap_workspace.py:78–170

属性详情Property Detail

is_persistent

def is_persistent() -> bool

读取 is_persistent 属性。

Whether the workspace files survive close.

返回Returns bool
返回布尔值,表示判断结果。Returns a boolean result.
源码Source agentscope/workspace/_bubblewrap/_bubblewrap_workspace.py:187–189

方法详情Method Detail

initialize

async def initialize() -> None
async

初始化 BubblewrapWorkspace 实例。

Initialize and clean up partial resources on failure.

返回Returns None
无返回值。No value is returned.
源码Source agentscope/workspace/_bubblewrap/_bubblewrap_workspace.py:290–301

get_instructions

async def get_instructions() -> str
async

获取指令。

Return the system-prompt fragment for this workspace.

返回Returns str
返回字符串结果。Returns a string.
源码Source agentscope/workspace/_bubblewrap/_bubblewrap_workspace.py:336–338
基于官方固定版本源码静态生成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.