autogen.coding.DockerCommandLineCodeExecutor
DockerCommandLineCodeExecutor
(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:Name | Description |
---|---|
image | Docker image to use for code execution. Defaults to “python:3-slim”. Type: str Default: ‘python |
container_name | Name of the Docker container which is created. If None, will autogenerate a name. Defaults to None. Type: str | None Default: None |
timeout | The timeout for code execution. Defaults to 60. Type: int Default: 60 |
work_dir | The working directory for the code execution. Defaults to Path(”.”). Type: Path | str Default: PosixPath(’.’) |
bind_dir | The directory that will be bound to the code executor container. Useful for cases where you want to spawn the container from within a container. Defaults to work_dir. Type: Path | str | None Default: None |
auto_remove | If true, will automatically remove the Docker container when it is stopped. Defaults to True. Type: bool Default: True |
stop_container | If true, will automatically stop the container when stop is called, when the context manager exits or when the Python process exits with atext. Defaults to True. Type: bool Default: True |
execution_policies | Type: dict[str, bool] | None 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
(Experimental) Execute the code blocks and return the result.
Parameters:Name | Description |
---|---|
code_blocks | The code blocks to execute. Type: list[CodeBlock] |
Type | Description |
---|---|
autogen.coding.base.CommandLineCodeResult | CommandlineCodeResult: The result of the code execution. |
restart
(Experimental) Restart the code executor.
stop
(Experimental) Stop the code executor.