Recover Source and Assets from a Bun Standalone Executable
On this page
A Bun executable can still contain readable JavaScript and embedded files. Before treating a compiled CLI as a black box, check what the compiler actually stored. Here we build a small parts-catalog CLI, extract its JavaScript and notice file with REA, and verify the recovered bytes. We also compare a build without the file import and one with bytecode enabled.
We tested REA 6.9.0, Bun 1.3.14 and Node 26.12.1 on macOS arm64. REA requires Node ^22.23.4 || ^24.22.1 || >=26.12.1. The walkthrough assumes rea --version reports 6.9.0; see the REA setup guide if needed. The compiler and REA are separate tools.
Build an app with something worth recovering
Our CLI combines two kinds of input: JSON bundled into JavaScript, and a text file imported as a file asset. Those should leave different evidence in the executable. Create this disposable project:
mkdir bun-recovery-demo
cd bun-recovery-demo
cat > catalog.json <<'JSON'
[{"name":"sensor","price":19},{"name":"relay","price":7}]
JSON
cat > notice.txt <<'TXT'
Offline parts catalog, sample data only.
TXT
cat > main.ts <<'TS'
import lookup from './catalog.json';
import note from './notice.txt' with { type: 'file' };
async function main() {
const name = process.argv[2] ?? 'sensor';
const row = lookup.find(x => x.name === name);
console.log(JSON.stringify({
name, price: row?.price ?? null,
notice: await Bun.file(note).text()
}));
}
main();
TS
bun build --compile main.ts --outfile catalog-app
./catalog-app relay
The command prints {"name":"relay","price":7,"notice":"Offline parts catalog, sample data only.\n"}. We run this executable because we just built it from the code shown here. You do not need to run an unknown executable to inspect it.
Find the entry module and the embedded file
rea inspect-artifact ./catalog-app --json > inventory.json
inspect-artifact returns a wrapper containing an inventory_artifact substep. Extract that graph before looking for modules; counting the outer JSON objects is misleading.
python3 - <<'PYCODE'
import json
result = json.load(open('inventory.json'))['normalized_result']
graph = next(s['evidence']['normalized_result'] for s in result['substeps']
if s['operation'] == 'inventory_artifact')
print(graph['manifest']['root_format'], graph['coverage'])
for item in graph['occurrences']:
meta = item.get('format_metadata') or {}
print(item['logical_path'], meta.get('region'), meta.get('entry_point'))
PYCODE
Our inventory reports bun-standalone, complete container-entry coverage and two modules. One is the JavaScript entry module, with a logical path ending in /catalog-app. The other is a file-loader module named like notice-0bddy2jj.txt. The JSON catalog is present in the bundled JavaScript, rather than a third independently recoverable catalog.json entry.
The root reports carrier mach-o-section and layout_revision: bun-1.3.9. That revision identifies the parser’s 52-byte record layout. It is not a detected compiler version: this executable was produced by Bun 1.3.14. Do not use it as a software-version fingerprint.
Extract the stored bytes and check them
rea extract-artifact ./catalog-app --json > extracted.json
Read the returned output_root rather than assuming an extraction directory. It is a new directory chosen by this invocation. The following check verifies every published artifact hash, compares the text asset with our original, and prints the recovered entry code:
python3 - <<'PYCODE'
import hashlib, json
from pathlib import Path
result = json.load(open('extracted.json'))['normalized_result']
root = Path(result['output_root'])
assert result['containment_verified']
for entry in result['artifacts']:
path = root / entry['relative_path']
data = path.read_bytes()
assert hashlib.sha256(data).hexdigest() == entry['sha256']
print(entry['relative_path'], len(data))
if path.suffix == '.txt':
assert data == Path('notice.txt').read_bytes()
elif entry['relative_path'].endswith('/catalog-app'):
text = data.decode('latin1')
assert 'sensor' in text and 'relay' in text
print(text)
PYCODE
In our run, the notice is 41 bytes and is byte-for-byte identical to notice.txt. The recovered entry contains the two catalog records and the CLI logic. Its JavaScript has compiler-generated variable names and bundle annotations; it is not our original TypeScript project. Imports can be inlined, paths rewritten, and TypeScript information removed. The asset and script hashes describe extracted content, not the original source tree.
This gives us a practical answer: the price data and notice are recoverable from the release executable. A secret placed in either location would not become private just because we used --compile.
Compare a build without the asset and one with bytecode
cat > noasset.ts <<'TS'
import lookup from './catalog.json';
console.log(JSON.stringify(lookup));
TS
bun build --compile noasset.ts --outfile noasset
rea inspect-artifact ./noasset --json > noasset.json
bun build --compile --bytecode main.ts --outfile catalog-bytecode
rea inspect-artifact ./catalog-bytecode --json > bytecode.json
rea extract-artifact ./catalog-bytecode --json > bytecode-extracted.json
The no-asset program is intentionally smaller: it only prints the catalog. Its inventory contains one module, with no notice-file entry. This distinguishes an embedded file from data the compiler incorporated into JavaScript.
The bytecode build still contains readable contents in this test and adds a separate .bytecode occurrence. REA also extracts those stored bytecode bytes. We did not decode them or recover JavaScript from bytecode. The readable script came from the executable’s contents region. A successful bytecode extraction therefore says nothing about decompilation success, and bytecode does not establish that every original source file remains recoverable.
Decide what you can safely claim
For this build we recovered the bundled JavaScript, the catalog values inside it, and an exact copy of the embedded notice. We did not reconstruct the TypeScript directory, package history or original identifiers. REA’s reader inventories and extracts supported stored regions; it does not execute the app or decode Bun bytecode. Different compiler layouts or build settings can change the result.
If the executable is unsupported, preserve the failure and compiler information rather than assuming there are no embedded sources. If it is untrusted, keep inspection offline and do not run extracted scripts. For browser bundles with external source maps, use the separate bundle recovery workflow; that is a different source of recoverable code.
Sources: REA 6.9.0 Bun standalone reader documentation, official REA release, and Bun executable documentation.