Skip to main content

DockerInterpreter

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

del

Destructor for the DockerInterpreter class. This method ensures that the Docker container is removed when the interpreter is deleted.

_initialize_if_needed

_create_file_in_container

_run_file_in_container

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

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

supported_code_types

Provides supported code types by the interpreter.

update_action_space

Updates action space for python interpreter

execute_command

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.