Skip to content

SandboxFactory

autogen.beta.tools.sandbox.factory.SandboxFactory #

Bases: Protocol

Per-call producer of a :class:Sandbox.

A factory is the only place :class:~autogen.beta.annotations.Variable parameters get resolved — backends themselves receive concrete values only. This isolates Variable / Context concerns from the execution surface.

Implementations return an async context manager so the underlying backend's lifecycle (container start / stop, remote sandbox creation / deletion) is explicit on every call.

open #

open(context=None)

Open a sandbox bound to context.

Variables registered on the factory (image, env_vars, credentials, …) are resolved against context.variables here. Backends that do not need Variables can ignore context.

Source code in autogen/beta/tools/sandbox/factory.py
def open(
    self,
    context: "ConversationContext | None" = None,
) -> AbstractAsyncContextManager[Sandbox]:
    """Open a sandbox bound to ``context``.

    Variables registered on the factory (image, env_vars, credentials,
    …) are resolved against ``context.variables`` here. Backends that
    do not need Variables can ignore ``context``.
    """
    ...