Sandbox
autogen.beta.tools.sandbox.base.Sandbox #
Bases: Protocol
Low-level execution backend.
A Sandbox runs an argv list inside a working directory and returns combined output with an exit code. It is the shared primitive on top of which the higher-level adapters are built:
- :class:
~autogen.beta.tools.sandbox.adapter.ShellAdapter— onerun(command)per shell command, applied filters, sync facade. - :class:
~autogen.beta.tools.sandbox.adapter.CodeAdapter— onerun(code, language)per code snippet, language matrix.
Implementations target local subprocesses, Docker containers, Daytona sandboxes, SSH, or anything else. Adding a new backend = one new Sandbox class. Both shell and code semantics come for free via the adapters.
Sandbox is async-only. Construction is cheap; backend resources are acquired on __aenter__ (or first call when __aenter__ is a no-op, as for :class:LocalSandbox) and released on __aexit__.
workdir property #
Working directory in which argv is executed, as seen inside the sandbox.
POSIX even on a Windows host so the same path is meaningful across backends.
host_workdir property #
Host-side view of :attr:workdir, when one exists.
Returns None for backends whose workdir is not visible on the host filesystem (e.g. remote Daytona sandboxes).
exec async #
Execute argv and return its output.
| PARAMETER | DESCRIPTION |
|---|---|
argv | Command and arguments. Always a normal argv list — no shell parsing happens on this layer. Callers that need shell features pass |
env | Extra environment variables merged into the process environment. |
timeout | Per-call timeout in seconds. TYPE: |
Source code in autogen/beta/tools/sandbox/base.py
put_file async #
Write content to path inside the sandbox.
path is relative to :attr:workdir (absolute paths are rejected to keep writes confined to the workdir).
Optional capability. Backends without filesystem write support raise :class:NotImplementedError.
Source code in autogen/beta/tools/sandbox/base.py
remove_file async #
Delete path inside the sandbox. Best-effort; never raises if the file is already gone.
path is relative to :attr:workdir. Used by the :class:~autogen.beta.tools.sandbox.adapter.CodeAdapter to clean up the temp files it writes for file-mode languages.