Skip to main content

Functions

FUNC code_interpreter

code_interpreter(code: str) -> ExecutionResult
Executes python code. Args:
  • code: The Python code to execute.

FUNC local_code_interpreter

local_code_interpreter(code: str) -> ExecutionResult
Executes python code in the cwd. Args:
  • code: The Python code to execute.

Classes

CLASS ExecutionResult

Result of code execution. Code execution can be aborted prior to spinning up an interpreter (e.g., if prohibited imports are used). In these cases, the success flag is set to False and the skipped flag is set to True. If code is executed, then success is set to true iff the exit code is 0, and the stdout and stderr outputs are set to non-None values. We also use the ExecutionResult object to communicate the result of static and dynamic analyses. Those are passed back using the analysis_result field. TODO: should we also be trying to pass back the value of the final expression evaluated, or the value of locals() and globals()?
Methods:

FUNC to_validationresult_reason

to_validationresult_reason(self)
Maps an ExecutionResult to a ValidationResult reason. TODO: Downstream use of this method is really hacky. A far better solution is for ExecutionResult to implement the ValidationResult interface.

CLASS ExecutionEnvironment

Abstract environment for executing Python code.
Methods:

FUNC execute

execute(self, code: str, timeout: int) -> ExecutionResult
Execute code and return result.

CLASS StaticAnalysisEnvironment

Safe environment that validates but does not execute code.
Methods:

FUNC execute

execute(self, code: str, timeout: int) -> ExecutionResult
Validate code syntax and imports without executing.

CLASS UnsafeEnvironment

Unsafe environment that executes code directly with subprocess.
Methods:

FUNC execute

execute(self, code: str, timeout: int) -> ExecutionResult
Execute code with subprocess after checking imports.

CLASS LLMSandboxEnvironment

Environment using llm-sandbox for secure Docker-based execution.
Methods:

FUNC execute

execute(self, code: str, timeout: int) -> ExecutionResult
Execute code using llm-sandbox.