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

OpenSandboxWorkspace

class OpenSandboxWorkspace(SandboxedWorkspaceBase)
源码Source agentscope/workspace/_opensandbox/_opensandbox_workspace.py:40–397

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

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, image: str = DEFAULT_IMAGE, api_key: str = '', domain: str = '', proto…
初始化 `OpenSandboxWorkspace` 实例。
Construct an :class:`OpenSandboxWorkspace`.

属性摘要Property Summary

属性Property说明Description
sandbox_id
获取沙箱标识。
OpenSandbox sandbox id, or ``None`` before initialize.

方法摘要Method Summary

方法Method说明Description
async def get_instructions() -> strasync
获取指令。
Return the system-prompt fragment for this workspace.

构造器详情Constructor Detail

OpenSandboxWorkspace

def __init__(*, workspace_id: str | None = None, image: str = DEFAULT_IMAGE, api_key: str = '', domain: str = '', protocol: Literal['http', 'https'] = 'http', request_timeout_seconds: float | None = DEFAULT_REQUEST_TIMEOUT, timeout_seconds: int = DEFAULT_TIMEOUT, gateway_port: int = DEFAULT_GATEWAY_PORT, env: dict[str, str] | None = None, sandbox_metadata: dict[str, str] | None = None, resource: dict[str, str] | None = None, entrypoint: list[str] | None = None, network_policy: NetworkPolicy | None = None, extra_pip: list[str] | None = None, instructions: str = DEFAULT_WORKSPACE_INSTRUCTIONS, default_mcps: list[MCPClient] | None = None, skill_paths: list[str] | None = None) -> None

初始化 OpenSandboxWorkspace 实例。

The sandbox 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`)。Stable identifier; also stored in sandbox metadata for reattachment.
imagekw默认default DEFAULT_IMAGEstr图像(类型 `str`)。OpenSandbox image used when creating a fresh sandbox.
api_keykw默认default ''strAPI 密钥(类型 `str`)。OpenSandbox API key (`""` lets the SDK use its environment fallback).
domainkw默认default ''strdomain(类型 `str`)。Optional OpenSandbox server domain.
protocolkw默认default 'http'Literal['http', 'https']协议(类型 `Literal['http', 'https']`)。Protocol to use (http/https)
request_timeout_secondskw默认default DEFAULT_REQUEST_TIMEOUTfloat | None请求超时秒(类型 `float | None`)。SDK HTTP request timeout. `None` leaves the SDK default in effect.
timeout_secondskw默认default DEFAULT_TIMEOUTint超时秒数(类型 `int`)。Sandbox keep-alive and create/connect/resume timeout.
gateway_portkw默认default DEFAULT_GATEWAY_PORTint网关 port(类型 `int`)。TCP port the in-sandbox gateway listens on.
envkw默认default Nonedict[str, str] | Noneenv(类型 `dict[str, str] | None`)。Environment variables baked into newly-created sandboxes.
sandbox_metadatakw默认default Nonedict[str, str] | None沙箱元数据(类型 `dict[str, str] | None`)。Extra metadata merged with the workspace-id tag.
resourcekw默认default Nonedict[str, str] | None资源(类型 `dict[str, str] | None`)。OpenSandbox resource hints for newly-created sandboxes.
entrypointkw默认default Nonelist[str] | Noneentrypoint(类型 `list[str] | None`)。Entrypoint override for newly-created sandboxes.
network_policykw默认default NoneNetworkPolicy | Nonenetwork 策略(类型 `NetworkPolicy | None`)。Creation-time OpenSandbox network policy. Runtime egress mutation is intentionally left to a follow-up.
extra_pipkw默认default Nonelist[str] | Noneextra pip(类型 `list[str] | None`)。Extra Python packages installed into the gateway venv during bootstrap.
instructionskw默认default DEFAULT_WORKSPACE_INSTRUCTIONSstr指令(类型 `str`)。Instructions that will be injected into the system prompt, which should receive placeholders "{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.
源码Source agentscope/workspace/_opensandbox/_opensandbox_workspace.py:53–144

属性详情Property Detail

sandbox_id

def sandbox_id() -> str | None

获取沙箱标识。

OpenSandbox sandbox id, or None before initialize.

返回Returns str | None
返回str|None。Returns str none.
源码Source agentscope/workspace/_opensandbox/_opensandbox_workspace.py:147–149

方法详情Method Detail

get_instructions

async def get_instructions() -> str
async

获取指令。

Substitutes {workdir} in the configured template with the sandbox-side path (/workspace).

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