SandboxCodeTool
autogen.beta.tools.code.tool.SandboxCodeTool #
SandboxCodeTool(environment, name='run_code', *, description='Execute code in a sandboxed environment. Supported languages: {languages}.', middleware=())
Bases: Tool
Exposes a single run_code(code, language) function backed by a :class:CodeEnvironment — Daytona, Docker, or any other implementation of the protocol.
Unlike :class:CodeExecutionTool (which delegates execution to the LLM provider's built-in sandbox), SandboxCodeTool runs client-side, so it works on every provider regardless of native code-execution support.
There is no default backend: environment is required. The class name is a contract — it executes whatever the model writes, so it should only be wired to a backend that genuinely sandboxes execution. Use :class:~autogen.beta.extensions.daytona.DaytonaCodeEnvironment or :class:~autogen.beta.extensions.docker.DockerCodeEnvironment (or your own implementation of :class:CodeEnvironment).
| PARAMETER | DESCRIPTION |
|---|---|
environment | The execution backend. TYPE: |
name | Tool name shown to the model. Defaults to TYPE: |
description | Tool description shown to the model. TYPE: |
middleware | Tool middleware applied around each invocation. TYPE: |
Examples::
from autogen.beta.extensions.daytona import DaytonaCodeEnvironment
from autogen.beta.extensions.docker import DockerCodeEnvironment
# Hosted sandbox
code = SandboxCodeTool(DaytonaCodeEnvironment(image="python:3.12"))
# Local container
code = SandboxCodeTool(DockerCodeEnvironment(image="python:3.12-slim"))