coding.docker_commandline_code_executor
DockerCommandLineCodeExecutor
__init__
(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.
Arguments:
image
type, optional - Docker image to use for code execution. Defaults to “python:3-slim”.container_name
Optional[str], optional - Name of the Docker container which is created. If None, will autogenerate a name. Defaults to None.timeout
int, optional - The timeout for code execution. Defaults to 60.work_dir
Union[Path, str], optional - The working directory for the code execution. Defaults to Path(”.”).bind_dir
Union[Path, str], optional - 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.auto_remove
bool, optional - If true, will automatically remove the Docker container when it is stopped. Defaults to True.stop_container
bool, optional - 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.
Raises:
ValueError
- On argument error, or if the container fails to start.
timeout
(Experimental) The timeout for code execution.
work_dir
(Experimental) The working directory for the code execution.
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.
execute_code_blocks
(Experimental) Execute the code blocks and return the result.
Arguments:
code_blocks
List[CodeBlock] - The code blocks to execute.
Returns:
CommandlineCodeResult
- The result of the code execution.
restart
(Experimental) Restart the code executor.
stop
(Experimental) Stop the code executor.