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

DockerWorkspace

class DockerWorkspace(SandboxedWorkspaceBase)
源码Source agentscope/workspace/_docker/_docker_workspace.py:43–321

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

default_mcps and skill_paths are seed-time inputs and are not retained as instance state past :meth:initialize.

构造器摘要Constructor Summary

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

属性摘要Property Summary

属性Property说明Description
is_persistent
读取 `is_persistent` 属性。
``True`` iff a host bind-mount preserves the workspace.

方法摘要Method Summary

方法Method说明Description
async def get_instructions() -> strasync
获取指令。
Return the system-prompt fragment, formatted with the container-side ``{workdir}``.

构造器详情Constructor Detail

DockerWorkspace

def __init__(*, workspace_id: str | None = None, base_image: str = DEFAULT_BASE_IMAGE, host_workdir: str | None = None, node_version: str | None = None, extra_pip: list[str] | None = None, gateway_port: int = DEFAULT_GATEWAY_PORT, env: dict[str, str] | None = None, instructions: str = DEFAULT_WORKSPACE_INSTRUCTIONS, default_mcps: list[MCPClient] | None = None, skill_paths: list[str] | None = None, **kwargs: Any) -> None

初始化 DockerWorkspace 实例。

The workspace is not started here — call :meth:initialize (or use the workspace as an async context manager).

参数Parameters
名称Name类型Type说明Description
workspace_idkw默认default Nonestr | None工作区标识(类型 `str | None`)。Existing workspace identifier to adopt; `None` mints a fresh UUID.
base_imagekw默认default DEFAULT_BASE_IMAGEstr基类图像(类型 `str`)。Base Docker image. Must provide `python3` in `$PATH`.
host_workdirkw默认default Nonestr | Nonehost workdir(类型 `str | None`)。Host directory bind-mounted to `/workspace`. `None` makes the workspace ephemeral.
node_versionkw默认default Nonestr | None节点版本(类型 `str | None`)。Node.js image version to bake into the image.
extra_pipkw默认default Nonelist[str] | Noneextra pip(类型 `list[str] | None`)。Extra Python packages installed into the gateway venv at image-build time.
gateway_portkw默认default DEFAULT_GATEWAY_PORTint网关 port(类型 `int`)。TCP port the gateway listens on inside the container (no host port mapping).
envkw默认default Nonedict[str, str] | Noneenv(类型 `dict[str, str] | None`)。Environment variables to set inside the container.
instructionskw默认default DEFAULT_WORKSPACE_INSTRUCTIONSstr指令(类型 `str`)。System-prompt fragment template; supports `{workdir}`.
default_mcpskw默认default Nonelist[MCPClient] | None默认 mcps(类型 `list[MCPClient] | None`)。MCPs registered on first init when no persisted `.mcp` exists.
skill_pathskw默认default Nonelist[str] | None技能 paths(类型 `list[str] | None`)。Local skill dirs seeded into `skills/` on first init.
kwargsAny关键字参数(类型 `Any`)。The kwargs.
源码Source agentscope/workspace/_docker/_docker_workspace.py:52–132

属性详情Property Detail

is_persistent

def is_persistent() -> bool

读取 is_persistent 属性。

True iff a host bind-mount preserves the workspace.

返回Returns bool
返回布尔值,表示判断结果。Returns a boolean result.
源码Source agentscope/workspace/_docker/_docker_workspace.py:135–137

方法详情Method Detail

get_instructions

async def get_instructions() -> str
async

获取指令。

Return the system-prompt fragment, formatted with the container-side {workdir}.

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