agentscope.workspaceBubblewrapWorkspace
class BubblewrapWorkspace(SandboxedWorkspaceBase)
agentscope/workspace/_bubblewrap/_bubblewrap_workspace.py:52–658Bubblewrap 工作区,在隔离环境中安全执行代码和工具。位于 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.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
workspace_idkw默认default None | str | None | 工作区标识(类型 `str | None`)。Stable workspace identifier. |
host_workdirkw默认default None | str | None | host workdir(类型 `str | None`)。Host directory mounted at `/workspace`. Omit for an ephemeral workspace. |
host_cache_dirkw默认default None | str | None | host 缓存目录(类型 `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_PORT | int | None | 网关 port(类型 `int | None`)。TCP port used by the in-sandbox gateway. `None` allocates an available loopback port during initialization. |
share_netkw默认default True | bool | share net(类型 `bool`)。Must be `True` for this workspace because the TCP MCP gateway is reached across separate `bwrap` executions. |
envkw默认default None | dict[str, str] | None | env(类型 `dict[str, str] | None`)。Extra environment variables for sandboxed commands. |
extra_pipkw默认default None | list[str] | None | extra 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_INSTRUCTIONS | str | 指令(类型 `str`)。System-prompt fragment template. |
default_mcpskw默认default None | list[MCPClient] | None | 默认 mcps(类型 `list[MCPClient] | None`)。MCPs seeded on first initialization. |
skill_pathskw默认default None | list[str] | None | 技能 paths(类型 `list[str] | None`)。Local skill directories seeded on first initialization. |
agentscope/workspace/_bubblewrap/_bubblewrap_workspace.py:78–170属性详情Property Detail
is_persistent
def is_persistent() -> bool
读取 is_persistent 属性。
Whether the workspace files survive close.
agentscope/workspace/_bubblewrap/_bubblewrap_workspace.py:187–189方法详情Method Detail
initialize
async def initialize() -> None
初始化 BubblewrapWorkspace 实例。
Initialize and clean up partial resources on failure.
agentscope/workspace/_bubblewrap/_bubblewrap_workspace.py:290–301get_instructions
async def get_instructions() -> str
获取指令。
Return the system-prompt fragment for this workspace.
agentscope/workspace/_bubblewrap/_bubblewrap_workspace.py:336–338