Run JavaScript
Run custom JavaScript inside a workflow. The script runs in a sandboxed Deno runtime, so you can transform data between nodes, compute values or add logic without leaving the canvas. Node ID: code.run.
Writing code
The node card shows a read-only preview of the script. Click it, or select the node, to edit Code in the inspector, and use the expand button there for a larger editor. JavaScript is the only supported language.
- Connected inputs are available as the
inputsobject and directly by name: a value wired to a handle nameddata1is readable asdata1orinputs.data1. Every declared or wired identifier exists on every run. When an upstream node produced no value, its direct binding isnull, so don't wrap wired inputs intypeof ... !== "undefined"guards. Handle names that aren't valid identifiers stay reachable asinputs["..."]. - Values in the workflow's Environment are on the read-only
envobject, for exampleenv.API_HOST. A workspace variable reachesenvonly if the Environment names it. This isn't the process environment, and it never contains workspace secrets. - End the script with
returnto pass a value downstream. The returned value becomes theresultoutput. A script that returns nothing passes its inputs through unchanged. console.log,console.warn,console.infoandconsole.erroroutput is captured into thelogsoutput.console.warnalso shows as a run warning. At most 50 warning lines are kept, each capped at 1 KiB after secret redaction. A returnedwarningslist is treated the same way.
// A connection wired to the `records` handle
const items = records || [];
return {
count: items.length,
names: items.map((item) => item.name.toUpperCase()),
source: env.SOURCE_NAME,
};
{{ }} templates aren't resolved inside the code field: braces there are code. Wire dynamic values in as inputs.
Inputs
Wire any output into the node, and each connection becomes a named input the script can read. There's no fixed input schema.
A dedicated chunks input, collapsed by default, accepts a live stream and switches the node into streaming mode.
Outputs
| Output | Description |
|---|---|
| result | The value returned by the script |
| logs | Console output captured during execution |
| metrics | Execution metrics such as duration |
| emit | Values emitted per chunk in streaming mode |
logs, metrics and emit are collapsed by default. Expand them on the node to wire them.
The Inputs and outputs section declares typed output ports over result: extract values by path, attach a schema and pick the mismatch policy. Fail node fails the step when the value doesn't match, and Warn records a warning.
Node settings
| Setting | Description | Default |
|---|---|---|
| Memory Limit (MB) | Memory the step reserves from the execution pool, 1 to 256. Only Kubernetes enforces a limit, as described below | 32 |
| CPU Quota | CPU for the step, 0.1 to 2.0. 1.0 is one core. Only Kubernetes enforces a limit, as described below | 1.0 |
| Parallel executions | How many executions of this node may run at the same time in this workflow, 1 to 10. It doesn't limit workflow runs | 1 |
| Allow Network Access (self-host) | Permit direct access to the allowlisted hosts on trusted self-hosted installations | Off |
| Network Allowlist | Comma-separated public hosts the code may reach when network access is on. A bare host means HTTPS on port 443. Empty means no egress |
On Kubernetes, a step's Size sets its CPU and memory limits. Without a Size, a plan with custom runner shapes turns these two settings into container limits, at no less than 512 MB and 0.25 core, so every Memory Limit (MB) value gives a 512 MB container. Other plans get the deployment's allocation. Docker and Native set no CPU or memory limit.
The Execution group at the bottom of the node's settings holds what every node shares: see Node settings. Step timeout (ms) is 60,000 by default for this node.
Streaming mode
Wire a live stream into the chunks input and the script runs once per chunk instead of once per run. Three inputs are available on each run:
chunk: the current chunkstate: the value carried over from the previous chunk,nullon the firstindex: the 0-based chunk index
The script's return value controls the stream:
{ emit: value }: sendvalueout theemitport. Include astatekey to carry a value to the next chunk{ state: value }: carry state and emit nothing{ done: true }: stop the stream- Anything else: skip the chunk
When the stream ends, result carries the final state. A script error stops the stream and fails the node.
Built-in helpers
Every script has a rollout helper object for producing the data shapes other nodes expect:
rollout.message(role, text): a chat messagerollout.messageList(value): normalize an array, or a single value, into a message listrollout.attachmentRef(descriptor): an attachment referencerollout.validate(shape, value): structural check against a shape, returning{ valid, errors }rollout.example(shape)androllout.shapes: bundled examples and the available shape names
Security and limits
- Code runs in a locked-down sandbox that refuses file APIs and process-environment access. It gets a container of its own on hosted Rollout and on a self-hosted installation that denies Native, which a new Compose install does. Otherwise it's a subprocess of the Rollout server.
- Network access is denied by default. Allow Network Access (self-host) is for trusted self-hosted installations, and a hosted workflow must use the HTTP request node. When it's on, egress goes only to the allowlisted hosts, never everywhere. Private, loopback and cloud-metadata hosts are always blocked, and an enabled workspace runtime allowlist narrows the list further.
- Remote modules don't load. An
import(),new Worker()ornpm:specifier for a remote module fails, with or without network access. Animport()with a literal path can still load local JavaScript or JSON files the process can read. - A script is capped at 10 seconds, per chunk in streaming mode. A timer still pending when the script returns counts, so clear it.
- Scripts are limited to 50,000 characters.
- A script's console output and result share a 1 MiB limit. Past it the step stops and fails with
output_too_large. eval(...),Function(...),require(...),__dirname,__filename,process.xandglobal.xare rejected before execution. The check reads the source as text, so a string or comment that contains one is rejected too. Longer names such asmyFunction(...)pass, and so does aprocessorglobalproperty of another object, such asrow.process.name. The other names are rejected as properties too, sorow.eval(...)fails.- Code executions are rate limited per workspace, 60 per minute by default.
Troubleshooting
Execution timeout
- A single script execution is capped at 10 seconds. Reduce the work per run or split it across nodes.
- Raising Step timeout (ms) extends the node's overall budget, which matters in streaming mode, and leaves the per-script cap alone.
Missing output
resultcarries the script's return value, so make sure the script ends withreturn.- Check declared output paths for typos.
Security policy violation
- Remove the blocked patterns listed under Security and limits.
- The script may have tried file, environment or non-allowlisted network access.
Rate limited
- Too many code executions in a short window. Space out runs or turn on Retry on Failure.