DockerCommandLineCodeExecutor

DockerCommandLineCodeExecutor(
    image: str = 'python:3-slim',
    container_name: Optional[str] = None,
    timeout: int = 60,
    work_dir: Optional[Union[Path, str]] = None,
    bind_dir: Optional[Union[Path, str]] = None,
    auto_remove: bool = True,
    stop_container: bool = True,
    execution_policies: Optional[dict[str, bool]] = None
)

(Experimental) A code executor class that executes code blocks and returns the result.
(Experimental) A code executor class that executes code through a command line environment in a Docker container.
The executor first saves each code block in a file in the working directory, and then executes the code file in the container.
The executor executes the code blocks in the order they are received.
Currently, the executor only supports Python and shell scripts.
For Python code, use the language “python” for the code block.
For shell scripts, use the language “bash”, “shell”, or “sh” for the code block.

Parameters:
NameDescription
imageType: str

Default: ‘python
container_nameType: Optional[str]

Default: None
timeoutType: int

Default: 60
work_dirType: Optional[Union[Path, str]]

Default: None
bind_dirType: Optional[Union[Path, str]]

Default: None
auto_removeType: bool

Default: True
stop_containerType: bool

Default: True
execution_policiesType: Optional[dict[str, bool]]

Default: None

Class Attributes

DEFAULT_EXECUTION_POLICY



LANGUAGE_ALIASES



Instance Attributes

bind_dir


(Experimental) The binding directory for the code execution container.

code_extractor


(Experimental) Export a code extractor that can be used by an agent.

timeout


(Experimental) The timeout for code execution.

work_dir


(Experimental) The working directory for the code execution.

Instance Methods

execute_code_blocks

execute_code_blocks(self, code_blocks: list[CodeBlock]) -> CommandLineCodeResult

(Experimental) Execute the code blocks and return the result.

Parameters:
NameDescription
code_blocksThe code blocks to execute.

Type: list[CodeBlock]
Returns:
TypeDescription
autogen.coding.base.CommandLineCodeResultCommandlineCodeResult: The result of the code execution.

restart

restart(self) -> None

(Experimental) Restart the code executor.


stop

stop(self) -> None

(Experimental) Stop the code executor.