/bnsql:pythonfrom bnsql
Execute Python inside Binary Ninja via bnsql. Use when SQL surfaces are insufficient and direct Binary Ninja API access is needed via Python snippets or scripts.
Ships in bnsql. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
Run Python against the live Binary Ninja session from SQL, for anything the SQL surfaces don't cover (custom algorithms, BN APIs not exposed as tables, UI automation).
| Function | Description |
|---|---|
bnsql_python(code[, sandbox]) | Execute a Python snippet; returns captured stdout as text |
bnsql_python_file(path[, sandbox]) | Execute a Python file; returns captured stdout as text |
Python execution is disabled by default (arbitrary code exec). Enable it per session:
UPDATE runtime_settings SET value='1' WHERE key='enable_python';
Bound a chatty/runaway snippet's captured output:
UPDATE runtime_settings SET value='65536' WHERE key='python_output_max'; -- cap stdout and stderr at 64 KiB each
UPDATE runtime_settings SET value='0' WHERE key='python_output_max'; -- unbounded (default)
bnsql_python runs in-process wherever bnsql runs: the Binary Ninja GUI
plugin and the headless CLI/--http/--mcp runtimes. In every case the live
BinaryView and the binaryninja API are loaded, so your Python sees the same
analysis the session holds. (Measured: InitPlugins() registers the python3
scripting provider headlessly; execution with a bound BinaryView works
end-to-end.)
One environment requirement: the process must hold a single
binaryninjacore.dll — the one in the Binary Ninja install directory. A copied
core DLL sitting next to the executable splits Binary Ninja's provider registry
(the exe binds the copy while BN's Python side binds the install-dir core), which
silently hides the provider. Remove any such copy and set BN_INSTALL_DIR; it is
never a license-tier problem, so do not advise an upgrade.
Two independent conditions must both hold, and enable_python alone is not enough:
SELECT value FROM runtime_settings WHERE key = 'enable_python'; -- the gate
GET /status reports python_available — whether a provider exists in that
process at all. enable_python: true with python_available: false means the
process is in the split-registry state above (or BN's python plugin failed to
load) — fix the environment. Read both rather than probing with a throwaway
snippet and parsing the error.
UPDATE runtime_settings SET value='1' WHERE key='enable_python';
-- Snippet: the current BinaryView is available as `bv` (BN console magic).
SELECT bnsql_python('print(len(list(bv.functions)))');
-- Reach an API not exposed as a table.
SELECT bnsql_python('print([s.name for s in bv.sections.values()][:5])');
-- Run an existing script file.
SELECT bnsql_python_file('C:/scripts/triage.py');
-- Isolated, persistent namespace: state survives across calls with the same key.
SELECT bnsql_python('counter = globals().get("counter", 0) + 1; print(counter)', 'alpha');
Each sandbox key is an isolated, persistent Python namespace:
A Python exception is surfaced as a SQL error (the traceback text):
SELECT bnsql_python('raise RuntimeError("boom")'); -- SQL error: ...RuntimeError: boom
Binary Ninja accepts or rejects the input synchronously, then runs accepted snippets asynchronously while bnsql waits for completion:
sys.stderr.write(...) or a warning) does not turn a completed snippet into a
failure; the function still returns captured stdout.| Use case | Best tool | Why |
|---|---|---|
| Query / filter / aggregate / join | SQL | purpose-built (funcs, xrefs, callees, …) |
| Custom algorithms | Python | graph walks, bespoke pattern matching |
| BN APIs not exposed as tables | Python | reach anything on bv / the BN API |
| UI automation (navigate, views) | Python | binaryninjaui from the plugin |
Reuse existing .py scripts | Python | run them as-is via bnsql_python_file |
connect — runtime/PRAGMA surface, routing.ui-context — get_ui_context_json() also uses the same GUI Python bridge.What SKILL.md sets; muted values are Claude Code's defaults
Other plugins' skills for the same job
npx claudepluginhub 0xeb/bnsql-skills --plugin bnsql11 skills in this plugin
/analysisBNSQL analysis workflows: triage, security audit, crypto/network detection, multi-table queries./annotationsEdit Binary Ninja databases: comments, renames, types, patches. Mutations require SELECT save() to persist (explicit-save model, v0.0.9+)./connectConnect to Binary Ninja databases and bootstrap sessions. Use when starting analysis, routing to other skills, or setting up CLI/HTTP/MCP connections./dataQuery Binary Ninja strings, bytes, and binary patterns. Use the byte_search table for fast byte-pattern search./decompilerDecompile Binary Ninja functions via HLIL: pseudocode text, local variables, call sites. Always filter by func_addr./disassemblyQuery Binary Ninja disassembly: functions, segments, instructions, blocks. Use for code-level analysis and instruction inspection.