Skip to content

CodeEnvironment

autogen.beta.tools.code.environment.base.CodeEnvironment #

Bases: Protocol

Backend that runs source code on behalf of :class:SandboxCodeTool.

Implementations may target a local subprocess, a remote sandbox (Daytona, e2b, …), a container, or anything else — :class:SandboxCodeTool only depends on this protocol.

supported_languages property #

supported_languages

Languages this environment is willing to run.

Surfaced in the tool description so the LLM knows what to ask for.

run async #

run(code, language, *, context=None)

Execute code in language.

context is the active conversation context, forwarded by :class:SandboxCodeTool so backends can resolve :class:~autogen.beta.annotations.Variable markers from context.variables (e.g. per-tenant credentials). Backends with no runtime-configurable parameters can ignore it.

Source code in autogen/beta/tools/code/environment/base.py
async def run(
    self,
    code: str,
    language: CodeLanguage,
    *,
    context: "ConversationContext | None" = None,
) -> CodeRunResult:
    """Execute *code* in *language*.

    ``context`` is the active conversation context, forwarded by
    :class:`SandboxCodeTool` so backends can resolve
    :class:`~autogen.beta.annotations.Variable` markers from
    ``context.variables`` (e.g. per-tenant credentials). Backends with
    no runtime-configurable parameters can ignore it.
    """
    ...