execute_custom_code
Run custom Python and pandas code on Excel workbooks or sheets to perform tailored data analysis, transformations, and retrieve results.
Instructions
Execute sandboxed Python/pandas code against a workbook or sheet and return result.
Args:
file_path: Path to source workbook to load into the sandbox.
code: Python code string. Sandbox exposes df (pandas.DataFrame), pd (pandas), np (numpy).
sheet: Optional sheet name to load into df. If omitted, the first sheet or a default is used.
output_file: Optional path to write results back to a workbook.
Returns:
dict: Execution result, typically containing result (from user code), stdout and errors.
Raises: ValueError: If code fails safety checks in the sandbox.
Notes: - High-risk: sandbox uses AST checks — document the allowed AST nodes and forbidden names. - Recommend returning a short example snippet of a safe operation in the route docs.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| code | Yes | ||
| sheet | No | ||
| file_path | Yes | ||
| output_file | No |