Skip to content

LocalEnvironment

autogen.beta.tools.sandbox.environment.LocalEnvironment #

LocalEnvironment(path=None, *, cleanup=None, timeout=60, max_output=100000, env_vars=None, languages=('python', 'bash'))

Bases: SingletonFactory

Local-subprocess backend — the default environment for :class:~autogen.beta.tools.SandboxShellTool.

A :class:~autogen.beta.tools.sandbox.SandboxFactory over a single :class:LocalSandbox with a fixed working directory. Hand it to a tool the same way you would a :class:DockerEnvironment / :class:DaytonaEnvironment::

shell = SandboxShellTool(LocalEnvironment("/tmp/proj"), allowed=["git"])

Commands run via subprocess on the host, so there is no real isolation — that is why :class:SandboxShellTool (which filters commands) defaults to it, but :class:SandboxCodeTool (which runs arbitrary model-written code) does not and requires an explicit backend.

PARAMETER DESCRIPTION
path

Working directory. None creates a temporary directory.

TYPE: str | PathLike[str] | None DEFAULT: None

cleanup

Delete path on close. Defaults to True for an auto temp dir, False for an explicit path.

TYPE: bool | None DEFAULT: None

timeout

Default per-command timeout in seconds.

TYPE: float DEFAULT: 60

max_output

Maximum characters in a single command's output.

TYPE: int DEFAULT: 100000

env_vars

Environment variables merged into every command.

TYPE: dict[str, str] | None DEFAULT: None

languages

Informational language list for the sandbox.

TYPE: tuple[CodeLanguage, ...] DEFAULT: ('python', 'bash')

Source code in autogen/beta/tools/sandbox/environment.py
def __init__(
    self,
    path: str | os.PathLike[str] | None = None,
    *,
    cleanup: bool | None = None,
    timeout: float = 60,
    max_output: int = 100_000,
    env_vars: dict[str, str] | None = None,
    languages: tuple[CodeLanguage, ...] = ("python", "bash"),
) -> None:
    super().__init__(
        LocalSandbox(
            path,
            cleanup=cleanup,
            timeout=timeout,
            max_output=max_output,
            env_vars=env_vars,
            languages=languages,
        )
    )

sandbox property #

sandbox

The wrapped sandbox instance.

aclose async #

aclose()

Close the underlying :class:LocalSandbox (deletes its workdir when cleanup was set). Safe to call multiple times.

Source code in autogen/beta/tools/sandbox/environment.py
async def aclose(self) -> None:
    """Close the underlying :class:`LocalSandbox` (deletes its workdir
    when ``cleanup`` was set). Safe to call multiple times."""
    await self.sandbox.aclose()

open async #

open(context=None)
Source code in autogen/beta/tools/sandbox/factory.py
@asynccontextmanager
async def open(
    self,
    context: "ConversationContext | None" = None,
) -> AsyncIterator[Sandbox]:
    del context
    yield self._sandbox