New260+ blocks and 240+ tools are now fully documented
DocumentationReferenceCore BlocksInputs & Outputs
Block

Function Block

Run custom logic

Execute custom JavaScript or TypeScript code within your workflow to transform data or implement complex logic. Use it whenever built-in blocks are too rigid — parse API responses, reshape JSON, run date math, filter arrays, or call Node.js built-ins directly.

Overview

PropertyValue
Typefunction
Categoryblocks
Color#FF402F

When to Use

  • Transform or reshape data between blocks (parse JSON, extract fields, format strings)
  • Perform calculations, date math, or string manipulation
  • Filter, sort, or aggregate arrays before passing them to the next block
  • Build custom API request logic using fetch and env-var credentials
  • Process and clean upstream block outputs that don't match downstream expectations
  • Implement reusable helper logic that can be wired anywhere in the workflow

Configuration

Code Editor

The single configuration surface is a full-featured code editor where you write the body of an async function(params, environmentVariables). You do not write the function signature itself — only the body.

Accessing workflow inputs and previous block outputs

Reference any resolved input value or upstream block output using double-brace syntax directly in the code body:

// Read an input mapped from an upstream block
const raw = {{agent_1.content}};

// Read a workspace environment variable / secret
const apiKey = {{MY_API_KEY}};

const parsed = JSON.parse(raw);
return {
  names: parsed.users.map(u => u.name),
  count: parsed.users.length,
};

Important rules enforced by the runtime:

  • Use {{paramName}} to read an input parameter or upstream block output. Do not write params.paramName.
  • Use {{ENV_VAR_NAME}} to read an environment variable. Do not write environmentVariables.VAR_NAME.
  • Never wrap {{...}} placeholders in quotes — the runtime substitutes them before execution, so adding quotes around a string placeholder will produce a quoted literal string inside another string.
  • Write only the function body. No async function wrapper, no import/require (except Node.js built-ins such as crypto or fs).
  • Always return a value if you need the result in a downstream block.
  • Use console.log() freely — output is captured in stdout and appears in execution logs.
  • Throw an Error to mark the block as failed and halt the workflow at this step.

The editor includes an AI wand that generates code from a plain-language description. It is aware of the {{...}} reference syntax and will produce correct placeholders.

Inputs & Outputs

  • Inputs:

    • code (string) — JavaScript/TypeScript code to execute (the function body)
    • timeout (number) — Execution timeout in milliseconds (default: 10 000 ms)
  • Outputs:

    • result (json) — Return value from the executed JavaScript function; can be any JSON-serialisable value (object, array, string, number, boolean)
    • stdout (string) — Console log output and debug messages captured during function execution

Reference outputs in downstream blocks as {{function_1.result}} or {{function_1.stdout}} (replace function_1 with the actual block name).

Tools

Function Execute (function_execute) — Executes JavaScript code in a secure, sandboxed environment with proper isolation and resource limits. Posts the code body plus resolved variable values to /api/function/execute, enforces a configurable timeout (default 10 s), and returns both the function's return value (result) and all console.log output (stdout). Environment variables and upstream block data are injected into the sandbox at runtime and are never exposed to the network.

YAML Example

function_1:
  type: function
  name: "Parse and summarise API response"
  inputs:
    code: |
      const items = {{api_block.response.results}};
      const summary = items.map(i => `${i.title}: $${i.price}`).join('\n');
      return {
        message: `Found ${items.length} items:\n${summary}`,
        total: items.reduce((sum, i) => sum + i.price, 0),
      };
    timeout: 10000
  connections:
    outgoing:
      - target: slack_1