Documentation Index
Fetch the complete documentation index at: https://docs.camel-ai.org/llms.txt
Use this file to discover all available pages before exploring further.
DockerInterpreter
class DockerInterpreter(BaseInterpreter):
A class for executing code files or code strings in a docker container.
This class handles the execution of code in different scripting languages
(currently Python and Bash) within a docker container, capturing their
stdout and stderr streams, and allowing user checking before executing code
strings.
Parameters:
- require_confirm (bool, optional): If
True, prompt user before running code strings for security. Defaults to True.
- print_stdout (bool, optional): If
True, print the standard output of the executed code. Defaults to False.
- print_stderr (bool, optional): If
True, print the standard error of the executed code. Defaults to True.
init
def __init__(
self,
require_confirm: bool = True,
print_stdout: bool = False,
print_stderr: bool = True
):
del
Destructor for the DockerInterpreter class.
This method ensures that the Docker container is removed when the
interpreter is deleted.
_initialize_if_needed
def _initialize_if_needed(self):
_create_file_in_container
def _create_file_in_container(self, content: str):
_run_file_in_container
def _run_file_in_container(self, file: Path, code_type: str):
cleanup
Explicitly stops and removes the Docker container.
This method should be called when you’re done with the interpreter
to ensure proper cleanup of Docker resources.
run
def run(self, code: str, code_type: str = 'python'):
Executes the given code in the container attached to the
interpreter, and captures the stdout and stderr streams.
Parameters:
- code (str): The code string to execute.
- code_type (str): The type of code to execute (e.g., ‘python’, ‘bash’). (default: obj:
python)
Returns:
str: A string containing the captured stdout and stderr of the
executed code.
_check_code_type
def _check_code_type(self, code_type: str):
supported_code_types
def supported_code_types(self):
Provides supported code types by the interpreter.
update_action_space
def update_action_space(self, action_space: Dict[str, Any]):
Updates action space for python interpreter
execute_command
def execute_command(self, command: str):
Executes a command in the Docker container and returns its output.
Parameters:
- command (str): The command to execute in the container.
Returns:
str: A string containing the captured stdout and stderr of the
executed command.