execute
Run Python scripts in Ghidra's PyGhidra environment to analyze or modify programs, with full API access and captured output.
Instructions
Execute a Python snippet in Ghidra's scripting environment.
The snippet runs inside Ghidra with full access to the Ghidra API via
PyGhidra.
Available variables:
- currentProgram: exactly one program, selected via the required
`program` argument
- flat: FlatProgramAPI-compatible script object
- toAddr(value): convert an address, function, symbol, or exact
function/label name to an Address
- Helpers: getBytes, getDataAt, getFunctionAt, getFunctionContaining,
getInstructionAt, getReferencesTo, getReferencesFrom
- state, monitor: Ghidra script state and task monitor
All Ghidra Java classes can be imported, e.g.:
from ghidra.program.model.symbol import SymbolType
from ghidra.app.decompiler import DecompInterface
Modifications are auto-wrapped in a transaction.
Use print() to return output.
The response includes:
- output: stdout captured from the snippet
- stderr: stderr captured from the snippet
- error: traceback string if execution failed
Program selection is based on the current Ghidra project name/path, not
the original imported filename. Use `get_programs()` to discover available
open programs.
Args:
code: Python code to execute in Ghidra.
program: Required Ghidra project path or name to target.
timeout: Bridge execution timeout in seconds.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| code | Yes | ||
| program | Yes | ||
| timeout | No |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| result | Yes |