Node Details

  • Name: CustomFunction_Utilities

  • Label: Custom JS Function

  • Type: CustomFunction

  • Category: Utilities

  • Version: 3.0

Input Parameters

  1. Input Variables (optional)

    • Type: JSON

    • Description: Input variables that can be used in the function with a ‘prefix(e.g.,' prefix (e.g., var)

    • Accepts variables and lists

  2. Function Name (optional)

    • Type: String

    • Description: A name for the custom function

    • Placeholder: “My Function”

  3. Additional Tools (optional)

    • Type: Tool

    • Description: Tools that can be used in the function with $tools.

      .invoke(args)

    • Accepts a list of tools

  4. Javascript Function

    • Type: Code

    • Description: The custom JavaScript function to be executed

Outputs

  1. Output

    • Types: string, number, boolean, json, array

    • Description: The result of the custom function execution

  2. Ending Node

    • Type: CustomFunction

    • Description: Indicates if this node is the final node in the workflow

Functionality

The Custom JS Function node creates a sandboxed environment to execute the provided JavaScript code. It offers the following capabilities:

  • Access to input variables, flow metadata, and custom tools

  • Ability to use both built-in Node.js modules and external dependencies (configurable via environment variables)

  • Secure execution using NodeVM to isolate the custom code

Usage

  1. Define input variables (if needed) in JSON format

  2. Optionally, provide a name for your function

  3. Add any additional tools required by your function

  4. Write your custom JavaScript function in the code editor

  5. The function’s return value will be passed as the output to the next node in the workflow

Security Considerations

  • The node uses NodeVM to create a sandboxed environment, limiting access to the host system

  • Built-in dependencies and external modules can be configured using environment variables:

    • TOOL_FUNCTION_BUILTIN_DEP: Comma-separated list of additional built-in modules to allow

    • TOOL_FUNCTION_EXTERNAL_DEP: Comma-separated list of additional external modules to allow

Example

// Access input variable
const name = $name;

// Use a tool
const translation = await $tools.translator.invoke(name);

// Return result
return `Hello, ${translation}!`;

This node is particularly useful for implementing custom logic, data transformations, or integrating external services that are not covered by other nodes in the system.