execute_idapython
Execute Python code or script files in IDA Pro to automate reverse engineering, query binary data, and return results using the full IDA API.
Instructions
Execute Python code or script file in IDA Pro context.
This tool sends Python code to the IDA Pro plugin for execution. The code runs in IDA's main thread with full access to all IDA API modules.
For long-running scripts, the tool polls for completion up to timeout
seconds. If the timeout is exceeded, a task_id is returned so you can check
status later using the check_task_status tool. Long scripts should poll the
injected mcp_cancelled() helper so they can be stopped cooperatively via
the cancel_ida_task tool.
Avoid calling ida_kernwin.ask_* and other interactive dialogs in scripts:
they block IDA's main thread until answered and freeze the whole task queue.
Args: params (ExecuteScriptInput): Validated input parameters containing: - code (Optional[str]): Python code string to execute - script_path (Optional[str]): Path to Python script file - capture_output (bool): Whether to capture stdout/stderr - instance_id (Optional[str]): Target IDA instance ID (e.g., "crackme.exe" or full ID) - port (Optional[int]): Target IDA instance port (e.g., 13338) - timeout (int): Maximum wait time in seconds (default: 600)
Returns:
str: JSON-formatted string containing:
- result: The value of the last expression (or a local result
variable), as a string or null
- stdout: Captured standard output
- stderr: Captured standard output (including errors)
- instance: The IDA instance that executed the code
- task_id: Present if script is still running or timed out
Examples: # Execute on default instance execute_idapython(code="print(idaapi.get_root_filename())")
# Execute on specific instance by database name
execute_idapython(code="len(list(idautils.Functions()))", instance_id="crackme.exe")
# Execute on specific instance by port
execute_idapython(code="idc.get_func_name(0x401000)", port=13339)
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| params | Yes |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| result | Yes |