Run code
The run code step: a sandboxed JavaScript function over the payload — the escape hatch when declarative transforms run out.
A sandboxed JavaScript function over the incoming payload — the escape hatch when set fields and reshape run out of road.
Config
One field: an arrow function. The editor validates it with the same parser the runtime uses.
The function must be an arrow function; its argument is the immediate upstream step's output, and its return value becomes this step's output:
(payload) => ({
...payload,
total: payload.items.reduce((sum, i) => sum + i.price, 0),
})
Spread the input (...payload) to carry upstream fields forward —
returning a fresh object drops everything you don't include. The
return value must be JSON-serializable (typically an object).
The sandbox
The function runs in a WebAssembly sandbox: no filesystem, no network, a frozen clock, 64 MB of memory, and a 5-second budget. It's a pure transform — for HTTP use web request; for messaging and storage use the dedicated steps.
The editor validates the code with the same parser the runtime uses, so anything that would fail at run time fails in the Inspector first.
Patterns
- Computed fields — totals, percentages, date math the declarative steps can't express.
- Odd formats — split a CSV string, parse a weird timestamp, build a composite key.
- Multi-field restructure — one function instead of a chain of set-fields rows.
Gotchas
payloadis the immediate upstream output only — there's no reaching back to earlier steps from code. Pull earlier values forward with set fields first.- Handle list inputs with 2+ items — code that assumes
payload.items[0]is the only item breaks on real data. - Return a plain object. Functions,
undefined, and class instances don't survive JSON serialization.