CodeExecutionToolkit

class CodeExecutionToolkit(BaseToolkit):

A toolkit for code execution.

Parameters:

  • sandbox (str): The environment type used to execute code. (default: subprocess)
  • verbose (bool): Whether to print the output of the code execution. (default: :obj:False)
  • unsafe_mode (bool): If True, the interpreter runs the code by eval() without any security check. (default: :obj:False)
  • import_white_list (Optional[List[str]]): A list of allowed imports. (default: :obj:None)
  • require_confirm (bool): Whether to require confirmation before executing code. (default: :obj:False)

init

def __init__(
    self,
    sandbox: Literal['internal_python', 'jupyter', 'docker', 'subprocess', 'e2b'] = 'subprocess',
    verbose: bool = False,
    unsafe_mode: bool = False,
    import_white_list: Optional[List[str]] = None,
    require_confirm: bool = False,
    timeout: Optional[float] = None
):

execute_code

def execute_code(self, code: str):

Execute a given code snippet.

Parameters:

  • code (str): The input code to the Code Interpreter tool call.

Returns:

str: The text output from the Code Interpreter tool call.

get_tools

def get_tools(self):

Returns:

List[FunctionTool]: A list of FunctionTool objects representing the functions in the toolkit.