Skip to content
Agentic Workflowdocs
v0.9.0Install free

nodes / builtin / core

JavaScript Code

Transform items with a few lines of JavaScript, in a sandbox with no network

Core ExtensionWeb appSince 0.9.0

Write a small JavaScript transform when no other step does what you need. It starts fast and runs in a sandbox: no network, no page access, no timers.

JavaScript Code runs your code in QuickJS, a small JavaScript engine compiled to WebAssembly, inside its own worker for each run of the step. The engine loads the first time the step runs.

At the top of Setup, a green card says what the step can reach: What it touches: nothing outside this step. No internet (use HTTP Request for calls), no web pages, tabs or your files, no connections or stored data, and how long it may run (Stops after …), with Change limits (the step’s Time limit). In Ready to run and on a Marketplace listing, the step shows as a calm grey Runs code in a sandbox row, not a warning.

Pick how it runs with Run:

  • Once for each item (the default): item is the current item and $itemIndex its position (from 0). Return the new item. Each item gets a fresh engine, so nothing leaks from one item to the next.
  • Once for all items: items is the whole list. Return the new list; each element becomes one item.

Both modes also get $workflow (id, name) and $execution (id, mode). The data you read is frozen JSON: change a copy ({ ...item }), not the original. Async code works: a returned promise is awaited.

What comes out:

  • An object is the item. Any other value becomes { result: value }. Returning nothing gives an empty item.
  • In Once for all items, the code must return a list, or the step fails with "Once for all items" code must return a list.

console.log() lines go to the run’s activity log (the first 200; after that, one line says the rest are hidden). console.warn() and console.error() show as warnings and errors.

  • A calculation or a reshaping that would take several steps otherwise.
  • Filtering or sorting with a rule that is easier to write than to click.
  • When you know JavaScript better than Python. Python Code does the same job in Python, but starts slower.

For counts, sums and averages per group, try Summarize items first: no code needed.

SettingTypeWhat it does
Run ChoiceOptions: Once for each item, Once for all items. Default: Once for each item
Code (required)CodeRead data with item / items. {{ }} isn’t replaced in code.
Time limit NumberDefault 10 s, up to 60 s.
Memory limit (MB) NumberDefault 64 MB, up to 256 MB.
Once for each item
// item is the current item; return the new one
return { ...item, total: item.qty * item.price };
Once for all items
// items is every item; return the new list
return items.filter((i) => i.active).map((i) => ({ name: i.name }));

Limits:

  • Time limit: 10 seconds by default, up to 60 seconds. A run that goes over stops with Stopped after 10 s (time limit).
  • Memory limit: 64 MB by default, up to 256 MB. Going over stops with Used more than 64 MB (memory limit).
  • Stop in the app ends the code at once.
  • Output

The items your code returned, one per object.

None. This node needs no connection and has no slots for other nodes.

The sandbox has no fetch, XMLHttpRequest, WebSocket, timers or imports. To call an API, put an HTTP Request step before or after this one.

  1. HTTP Request fetches a list of orders (one item per order).
  2. JavaScript Code, Once for each item: return { ...item, total: item.qty * item.price };
  3. Summarize items sums total per region.
  • Line 3, item 2: TypeError: …: the error names the line of your code and the item (counted from 1). Open the step’s Input to see that item.
  • 'fetch' is not defined: the sandbox has no network. Use HTTP Request for calls.
  • The output still shows {{ … }}: expressions are not replaced in code. Read the value from item.
  • “Once for all items” fails: return a list, for example return items;.
Edit page

Last updated:

Was this page useful?
Ask Aria about JavaScript Code