Inputs
The block passes every variable you map into it as one
inputs object. Whatever main returns becomes the block’s output. A minimal function reads its inputs and returns a plain object:
Outputs
Reference the returned value in a later block as
{{ steps.execute_code.result }}. If main returns an object, address each field by its key, such as {{ steps.execute_code.result.score }}.
Behavior
The block runs the exportedmain function once per run and waits for it to finish before continuing. An async function is awaited, so you can await inside main. The work still has to finish within the 100-second timeout. Code that runs past the timeout fails the block instead of returning a partial result.
The return value passes through exactly as written, including null, an empty object, or an empty array. Downstream blocks receive exactly what main returned, so a missing field reads as undefined rather than an error. The credit cost is variable and complexity-based, so heavier code costs more than a light transformation. Keep functions small and single-purpose.
Gotchas
- The function must be named
main. The block callsmain(inputs)by name. An unnamed function, a differently named export, or a default export will not run. Exportmainexactly, and read your data through itsinputsparameter rather than from any outer scope. - A thrown error fails the whole block. Any uncaught exception inside
mainstops the run at this block, so a single bad field can halt the workflow. Wrap risky parsing in atry/catchand return a marker value, such as{ error: true }, that a later If block can branch on. - Non-deterministic code makes runs hard to trust. Non-deterministic means the same input can produce a different result. When the result drives a write, calls to
Date.now(),Math.random(), or an external service can each return a different value on every run and every retry. Keep code that controls writes deterministic. Move randomness to the Random number block so the value is recorded in run history. - Long jobs hit the 100-second timeout. The block stops at 100 seconds and fails, so polling loops and large batch loops are the wrong fit. Split the work across a Loop block, or call an external service with Send HTTP request.
Examples
Normalizing a lead source field
This function maps inconsistent source labels onto one canonical value before the workflow writes the record. Canonical means the single agreed-on spelling you store, such asPaid search for every variant of that source.
inputs.source set to LI Ads, the block returns { "source": "Social" }. An Update record block then writes that value to the lead’s source attribute as {{ steps.execute_code.result.source }}.
Scoring a record from several attributes
This function combines three mapped variables into one explainable score for a deal owned by Priya Sharma.{ "score": 70 }. A downstream If block reads it as {{ steps.execute_code.result.score }} to route deals scoring 50 or higher to a sales-ready stage.