Skip to main content

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:

  • code str - The code to execute.
  • extra_globals Optional[dict] - Additional global variables.
  • supported_imports Optional[List[str]] - List of allowed modules.
  • function_name str - The name of the function to execute.
  • input_args Optional[List[Any]] - Positional arguments for the function.
  • input_kwargs Optional[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.