Skip to content

SandboxBase

autogen.beta.tools.sandbox.base.SandboxBase #

Bases: ABC

ABC with default implementations for the optional :class:Sandbox methods.

Concrete backends subclass :class:SandboxBase and override :meth:exec, :attr:workdir, :attr:host_workdir. They opt into streaming and file IO by overriding the relevant methods.

workdir abstractmethod property #

workdir

host_workdir abstractmethod property #

host_workdir

exec abstractmethod async #

exec(argv, *, env=None, timeout=None)
Source code in autogen/beta/tools/sandbox/base.py
@abstractmethod
async def exec(
    self,
    argv: list[str],
    *,
    env: dict[str, str] | None = None,
    timeout: float | None = None,
) -> ExecResult: ...

put_file async #

put_file(path, content)
Source code in autogen/beta/tools/sandbox/base.py
async def put_file(self, path: PurePosixPath, content: bytes) -> None:
    raise NotImplementedError(
        f"{type(self).__name__} does not support put_file. Override the method on the subclass."
    )

remove_file async #

remove_file(path)

Default cleanup: rm -f inside the sandbox.

Works on any POSIX backend that can exec. Backends with a native delete API (local filesystem, Daytona fs.delete_file) should override for directness. Never raises on a missing file.

Source code in autogen/beta/tools/sandbox/base.py
async def remove_file(self, path: PurePosixPath) -> None:
    """Default cleanup: ``rm -f`` inside the sandbox.

    Works on any POSIX backend that can ``exec``. Backends with a native
    delete API (local filesystem, Daytona ``fs.delete_file``) should
    override for directness. Never raises on a missing file.
    """
    if path.is_absolute():
        raise ValueError(f"Absolute paths are not allowed in remove_file: {path}")
    target = self.workdir / path
    await self.exec(["rm", "-f", str(target)])

aclose async #

aclose()

Default cleanup: nothing.

Backends that hold resources (containers, remote sandboxes) override this method.

Source code in autogen/beta/tools/sandbox/base.py
async def aclose(self) -> None:
    """Default cleanup: nothing.

    Backends that hold resources (containers, remote sandboxes)
    override this method.
    """