类class
agentscope.workspaceDaytonaBackend
class DaytonaBackend(BackendBase)
源码Source
agentscope/workspace/_daytona/_daytona_backend.py:23–167Daytona Backend,在隔离环境中安全执行代码和工具。位于 agentscope.workspace 包,继承自 BackendBase。核心成员包括 getcwd、exec_shell、read_file、write_file。
Only the three abstract primitives (exec_shell, read_file,
write_file) are implemented here; the derived filesystem helpers
are inherited from :class:BackendBase.
构造器摘要Constructor Summary
| 构造器Constructor | 说明Description |
|---|---|
def __init__(sandbox: Any, workdir: str) -> None | 初始化 `DaytonaBackend` 实例。 Initialize the Daytona backend. |
方法摘要Method Summary
| 方法Method | 说明Description |
|---|---|
async def getcwd() -> strasync | 返回 `getcwd` 结果。 Return the sandbox's default working directory. |
async def exec_shell(command: list[str], *, cwd: str | None = None, timeout: float | None = None) -> ExecResultasync | 执行 `exec_shell` 方法。 Run a program inside the sandbox via ``process.exec``. |
async def read_file(path: str) -> bytesasync | 设置读取文件。 Read a file from the sandbox via ``fs.download_file``. |
async def write_file(path: str, data: bytes) -> Noneasync | 执行写入文件相关操作。 Write *data* to a file inside the sandbox. |
构造器详情Constructor Detail
DaytonaBackend
def __init__(sandbox: Any, workdir: str) -> None
初始化 DaytonaBackend 实例。
Initialize the Daytona backend.
参数Parameters
| 名称Name | 类型Type | 说明Description |
|---|---|---|
sandbox | Any | 沙箱(类型 `Any`)。A started / attached Daytona sandbox object. |
workdir | str | workdir(类型 `str`)。Default working directory for `exec_shell` calls inside the sandbox. |
源码Source
agentscope/workspace/_daytona/_daytona_backend.py:39–50方法详情Method Detail
getcwd
async def getcwd() -> str
async
返回 getcwd 结果。
Overrides the base class default (which would shell out to pwd) with the cached workdir supplied at construction, avoiding a per-call sandbox round-trip.
str
返回字符串结果。`str`:
源码Source
agentscope/workspace/_daytona/_daytona_backend.py:54–65exec_shell
async def exec_shell(command: list[str], *, cwd: str | None = None, timeout: float | None = None) -> ExecResult
async
执行 exec_shell 方法。
command* is an argv list.
参数Parameters
| 名称Name | 类型Type | 说明Description |
|---|---|---|
command | list[str] | 命令(类型 `list[str]`)。Executable path/name followed by its arguments. |
cwdkw默认default None | str | None | cwd(类型 `str | None`)。Working directory inside the sandbox. When `None` the backend's default `workdir` is used. |
timeoutkw默认default None | float | None | 超时时间(类型 `float | None`)。Maximum number of seconds to wait. Daytona expects an integer timeout, so provided values are rounded up to the next integer second. |
ExecResult
返回ExecResult。`ExecResult`:
源码Source
agentscope/workspace/_daytona/_daytona_backend.py:67–122read_file
async def read_file(path: str) -> bytes
async
设置读取文件。
Read a file from the sandbox via fs.download_file.
参数Parameters
| 名称Name | 类型Type | 说明Description |
|---|---|---|
path | str | 路径(类型 `str`)。Path to the file inside the sandbox. |
bytes
返回字节。`bytes`:
- 可能抛出 `Exception`。`FileNotFoundError`:
- 可能抛出 `Exception`。If the path does not exist inside the sandbox.
源码Source
agentscope/workspace/_daytona/_daytona_backend.py:126–151write_file
async def write_file(path: str, data: bytes) -> None
async
执行写入文件相关操作。
Creates parent directories via exec_shell first.
参数Parameters
| 名称Name | 类型Type | 说明Description |
|---|---|---|
path | str | 路径(类型 `str`)。Destination path inside the sandbox. |
data | bytes | 原始字节到写入。The raw bytes to write. |
None
无返回值。No value is returned.
源码Source
agentscope/workspace/_daytona/_daytona_backend.py:153–167