New260+ blocks and 240+ tools are now fully documented
DocumentationReferenceTool IntegrationsCore & Utilities
Tool

Function

Execute custom JavaScript code in a secure sandboxed environment within your workflow

The Function block lets you run arbitrary JavaScript logic inside a secure, isolated sandbox at any point in your workflow. Use it to transform data, implement custom business rules, call external APIs, or bridge between blocks when no built-in tool covers your exact requirement.

Overview

PropertyValue
Typefunction
CategoryTool — Developer
AuthNone (the sandbox has no credentials; pass secrets via envVars)

Operations

OperationTool IDDescription
Function Executefunction_executeExecute a JavaScript function body in a sandboxed Node.js environment with configurable timeout and environment variable injection

Configuration

SettingTypeRequiredDescription
codestringYesThe JavaScript function body to execute. The code runs inside an async function(params, environmentVariables) { ... } context. Reference upstream block outputs and env vars using {{...}} placeholders (e.g. {{starter.value}}, {{MY_API_KEY}}).
timeoutnumberNoMaximum execution time in milliseconds before the sandbox forcibly terminates. Defaults to 10000 (10 seconds).
envVarsobjectNoKey/value map of environment variable names and their values to expose inside the function. Access them in code as {{ENV_VAR_NAME}}.
blockDataobjectNoResolved output data from upstream blocks — injected automatically by the executor for {{blockName.field}} resolution. You do not set this manually.
blockNameMappingobjectNoMaps human-readable block names to internal block IDs — injected automatically by the executor. You do not set this manually.

Outputs

FieldTypeDescription
resultjsonThe value returned by the last return statement in your function body. Can be any JSON-serializable value: string, number, object, or array.
stdoutstringCaptured output from all console.log() (and related) calls made during execution. Useful for debugging.

Example

[Starter] → [Function: transform data] → [Agent: summarize result]

Suppose the Starter receives a raw JSON payload from a webhook. Add a Function block with code that parses, filters, and reshapes the payload:

const records = {{starter.records}};
const apiKey  = {{INTERNAL_API_KEY}};

const filtered = records.filter(r => r.status === 'active');

const response = await fetch('https://internal.example.com/enrich', {
  method: 'POST',
  headers: { 'Authorization': `Bearer ${apiKey}`, 'Content-Type': 'application/json' },
  body: JSON.stringify({ items: filtered }),
});

if (!response.ok) throw new Error(`Enrich failed: ${response.status}`);
return await response.json();

The downstream Agent block then receives {{function.result}} — the enriched array — and can summarize or act on it without needing to know about the transformation details.

Tips

  • Return a value explicitly. The result output is whatever your return statement produces. If you forget return, result will be undefined.
  • Use console.log for debugging. Everything written to stdout is captured in the stdout output so you can inspect intermediate values without failing the workflow.
  • Inject secrets via envVars, not hardcoded strings. Map workspace environment variables to the envVars param (e.g. { "MY_KEY": "{{MY_API_KEY}}" }) and reference them in code as {{MY_KEY}}. This keeps secrets out of the code editor.
  • Respect the timeout. Long-running or recursive operations that exceed the timeout (default 10 s) will be killed and the block will error. Increase timeout for operations that legitimately take longer, but prefer delegating heavy I/O to dedicated tool blocks.
  • Standard Node.js built-ins are available (e.g. crypto, Buffer, URL). External npm packages are not importable — implement the logic inline or use fetch for remote resources.