agora.common.interpreters.restricted
execute_restricted
def execute_restricted(code: str,
extra_globals: Optional[dict] = None,
supported_imports: Optional[List[str]] = None,
function_name: str = 'run',
input_args: Optional[List[Any]] = None,
input_kwargs: Optional[dict] = None) -> Any
Executes restricted code with limited globals and supported imports.
Arguments:
codestr - The code to execute.extra_globalsOptional[dict] - Additional global variables.supported_importsOptional[List[str]] - List of allowed modules.function_namestr - The name of the function to execute.input_argsOptional[List[Any]] - Positional arguments for the function.input_kwargsOptional[dict] - Keyword arguments for the function.
Returns:
Any- The result of the executed function.
Raises:
ExecutionError- If an unsupported import is attempted or multiple results are registered.