nat.tool.code_execution.local_sandbox.local_sandbox_server#
Attributes#
Classes#
Status of code execution. |
|
Result of code execution. |
|
Response class that returns a JSON response with the given status code and result. |
Functions#
|
|
|
Execute Python code in a subprocess. |
|
Execute code in a subprocess. |
|
Main function to handle execution requests. |
|
Module Contents#
- app#
- logger#
- class CodeExecutionStatus#
-
Status of code execution.
Initialize self. See help(type(self)) for accurate signature.
- COMPLETED = 'completed'#
- ERROR = 'error'#
- TIMEOUT = 'timeout'#
- class CodeExecutionResult(/, **data: Any)#
Bases:
pydantic.BaseModel
Result of code execution.
Create a new model by parsing and validating input data from keyword arguments.
Raises [
ValidationError
][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.self
is explicitly positional-only to allowself
as a field name.- process_status: CodeExecutionStatus = None#
- class CodeExecutionResponse(status_code: int, result: CodeExecutionResult)#
Bases:
flask.Response
Response class that returns a JSON response with the given status code and result.
- classmethod with_error( ) CodeExecutionResponse #
- add_hsts_header(response)#
- execute_python( ) CodeExecutionResult #
Execute Python code in a subprocess.
- Args:
generated_code: The code to execute timeout: The timeout for the execution
- Returns:
CodeExecutionResult object containing the execution result
- execute_code_subprocess(generated_code: str, queue)#
Execute code in a subprocess.
- Args:
generated_code: The code to execute queue: The queue to put the result in
- do_execute(request: flask.Request) CodeExecutionResponse #
Main function to handle execution requests.
- Args:
request: Request object containing the execution request
- Returns:
CodeExecutionResponse object containing the execution result
- execute()#