Integration

Python or JavaScript code step? Choosing a language for custom logic

Before choosing between a Python or JavaScript code step, check whether you need code at all. Often, what needs a custom function in one integration tool is a built-in step in another. When you do need code, pick the language for the job: JavaScript for reshaping JSON, Python for exact money math and statistics, and Rhai for small rules you reuse, all in the same sandbox.

By Maria Soria, Manager of Customer Success

Python or JavaScript, pick by the job: 17 of 31 migrated scripts became built-in steps, three languages share one sandbox, and a Code step with Rhai, JavaScript and Python tabs maps reshaping JSON to JavaScript, exact money math to Python and reused rules to Rhai

When customers move to Neblex from another automation tool, one of the first things they ask me about is their existing scripts. My first answer is a question: what does each script do? Many of them exist only because the old tool had no native step for the job at the time, or because code was the simplest approach, such as replacing a long chain of native steps.

Here is how I help customers decide: when a built-in step does the job, which language to use when it doesn't, and what each one can and can't reach. I tested all three languages in a flow when writing this. We also migrated 31 scripts (the kinds customers bring us) into Neblex, and what happened to them runs through each section below.

Do you need a code step at all?

The scripts that turn into built-in steps tend to do the same few jobs: formatting a phone number, flattening a list, totaling orders per customer, checking a business rule. They were written as code because that was the only option, or the one that made the most sense then.

So before we port anything, I ask two questions about each script: what does it do to a record, in one sentence, and is there a built-in step that says the same thing? If you're coming from a pro-code automation tool, these are jobs I commonly see written as code that don't need code in Neblex:

The job that usually ends in a code stepBuilt-in step in Neblex
Format phone numbers to E.164, convert country names to ISO codesNormalize
Find fuzzy duplicates, like Jonathon and Jonathan SmithRemove duplicates
Validate JSON against a schema and list every errorValidate Records
Check an IBAN or a barcode (GTIN) check digitEdit text (built-in validators)
Calculate the median, a percentile or the standard deviation per groupGroup & summarize
Validate XML against an XSDXML
Parse an X12 850 purchase order and send a 997 acknowledgmentRead EDI, Acknowledge EDI
Generate a PDF invoice from a templateCreate PDF

In our test, we moved 31 scripts into Neblex, and 17 of them didn't need to stay code: a built-in step did the same job, with the same output on every record. Four of those relied on npm packages or Node modules, such as lodash and Node's crypto, so replacing them also removed a dependency to install and maintain.

A built-in step shows its settings in the editor, so anyone can see what it does without reading code.

Use a Code step for rules specific to your business that no step expresses: a validation that depends on several fields at once, a calculation your finance team defined, or exact money math. Keep the script to that rule, and let built-in steps do the work around it.

How the Code step works in each language

The Code step runs a script over the records a step receives. It offers three languages and two modes:

RhaiJavaScriptPython
Each recordThe script works on item and returns ittransform(item) returns the new recordtransform(item) returns the new record
All recordsfn step(batch), plus an optional fn finish(parts)transform(items) returns the new listtransform(items) returns the new list
Drop a recordLeave it out of what step returns (All records mode)Return nullReturn None
Reuse across flowsImported Transform Modules and the snippet libraryCopy the scriptCopy the script

Rhai is the default language. In Each record mode, a Rhai script always outputs one record per input record.

JavaScript code step: pros and cons

JavaScript is the language most people I work with have used, and it is a natural fit for JSON records. Object spread, map, filter, and regular expressions make reshaping a record short and readable. Code from Node-based automation tools usually needs only its wrapper changed, as pricing rules, lead scoring, and an order-splitting script did for us.

function transform(item) {
  if (item.qty === 0) return null;   // drop empty order lines
  const name = item.name.trim().split(/\s+/)
    .map(w => w[0].toUpperCase() + w.slice(1).toLowerCase()).join(' ');
  return { ...item, name, email: item.email.trim().toLowerCase() };
}

The trade-offs:

  • No packages. There is no require or npm, so you either write a helper into the script or replace it.
  • Numbers are binary floating point, so 0.1 + 0.2 isn't exactly 0.3. For money, work in integer cents or do the math in a Python step.

Python code step: pros and cons

Python reads almost like plain English, which helps when the person maintaining the code isn't the person who wrote it. Its standard library is the main reason to pick it: decimal for exact money math, statistics for averages and medians, re for text checks, hashlib for match keys, and datetime for arithmetic on dates from your data. A messy CSV export, invoice totals, an address parser, and dates in nine formats all ran unchanged in our test.

import re, decimal

def transform(item):
    total = decimal.Decimal(str(item["price"])) * item["qty"]
    item["total"] = str(total.quantize(decimal.Decimal("0.01")))
    item["email_valid"] = bool(re.fullmatch(r"[^@\s]+@[^@\s]+\.[a-z]{2,}", item["email"]))
    return item

The trade-offs:

  • Standard library only, and without its modules for files, the network and processes. Libraries you would normally install with pip, such as pandas or requests, aren't available.
  • No files, network, or subprocesses, so scripts that read a local file or call an API need those parts moved into connector steps.

Rhai code step: pros and cons

Rhai is a scripting language made for embedding in other software, and in Neblex it is the only one of the three with built-in reuse. You can save functions as a Transform Module and import it into any flow in your workspace. Each run loads the module's current version, so a fix reaches every flow that uses it. Our library of Rhai functions for dates, amounts, and match keys works this way.

fn step(batch) {
  let total = 0.0;
  for r in batch { total += r.total; }
  #{ n: batch.len(), total: total }
}
fn finish(parts) {
  let n = 0; let total = 0.0;
  for p in parts { n += p.n; total += p.total; }
  [#{ records: n, grand_total: total }]
}

Its All records mode also works differently. You write step(batch) for one batch of records and finish(parts) to combine the results, so a total or summary over many records is worked out batch by batch and combined at the end.

The trade-offs:

  • Fewer people know Rhai, and there are fewer examples online than for JavaScript or Python.
  • Its built-in functions are basic, so you write helpers yourself or import a module.
  • The syntax looks like JavaScript and Rust but isn't either, which trips people up at first.

Python or JavaScript code step: which language for which job

JobBest fitWhy
Reshape or clean JSON recordsJavaScriptShort, familiar syntax for objects and arrays
Code moved from a Node-based toolJavaScriptUsually only the wrapper changes
Money math that must be exactPythondecimal avoids floating-point rounding
Averages, medians, rankingPythonstatistics in the standard library
Code moved from a Python code stepPythonSame language, standard library included
A rule used in many flowsRhaiTransform Modules: write once, import everywhere
Totals or summaries over large record setsRhaiBatched step and finish
A parser or library shared by flows and AI agentsWebAssembly moduleCompiled, reusable, callable as an agent tool
A script that needs packages, files or other programsA script over SSH on your own serverRuns with what that host has installed

WebAssembly for reusable modules

Some logic is bigger than a script: reading a raw email and its attachments, parsing a fixed-width bank file, or redacting personal data before text reaches an AI model. For that, Neblex runs WebAssembly modules, small compiled files that take JSON in and return JSON out.

A module is written once, in Rust or another language that compiles to WebAssembly, and reused by any flow or called by an AI agent as a tool. It runs sandboxed like a Code step, with no access to files or the network. Modules are included in the Business and Enterprise plans. Our WebAssembly post covers the library we published.

Business rules that stay in code

These scripts from our migration test should stay in code, because each one is a rule specific to one business. Each ran in a Code step with only a transform wrapper added, and gave the same output as the original script on every record.

ScriptLanguage and modeWhat it doesResult
Pricing rulesJavaScript, Each recordPrice list, segment and volume discounts, promo codes and a price floor5 order lines priced; an unknown SKU and an invalid promo code flagged
Lead scoringJavaScript, Each recordWeighted points for email domain, job title, company size, country and demo requests, then a gradeScores of 100, 65, 32 and 0, graded A, B, D and D, with the reasons listed
Shipping allocationJavaScript, All recordsSplits orders into lines and shares out shipping by line value2 orders became 4 lines; $12.50 of shipping split $6.25, $5.12 and $1.13
Invoice totalsPython, Each recordExact money math with decimal, discounts and tax by regionTotals of 314.73, 27.86 and 1,000.00; an unknown region flagged
Address parserPython, Each recordSplits a one-line US or Canadian address into street, unit, city, region and postal code3 addresses parsed; 1 that couldn't be parsed flagged
Order validationJavaScript and Python, All records32 rules plus reference tables for 183 countries, US states, Canadian provinces, currencies and postal-code formatsIdentical results in both languages

Data also moves cleanly between languages. In a separate flow that passed records through Rhai, JavaScript, and Python steps in turn, every field each language added arrived intact in the next step. Numbers stayed numbers, and booleans and nested objects kept their types.

What code can't reach, and why that helps

In both JavaScript and Python, I tried to step outside the sandbox. Every attempt failed:

What I triedPythonJavaScript
Read or write a file, list a folderFailed: no file systemNo file functions available
Read environment variablesNone presentNo process object
Open a network connection or HTTP requestNo network supportNo fetch or require
Start a processNot availableNot available
Random numbersSeeded per run: a retry or replay repeats themSeeded per run: a retry or replay repeats them

The practical effect is that a Code step can only transform the records it is given. A script written by an AI assistant, copied from a forum, or inherited from a colleague can't send your data anywhere or read a credential. Connector steps make calls to other systems, using the connections you set up in Neblex.

This has a second benefit. A script's clock is fixed at its run's start and its random numbers are seeded per run, so a retry or replay of a run gets the same output from each Code step, which makes replaying a failed step safe.

Going past the sandbox

A Code step is more restricted than JavaScript in a browser tab, which can at least make web requests. That is deliberate. When a job needs more, Neblex offers two other options, so the Code step itself never gets access to files or the network.

Code steps and WebAssembly modules run sandboxed in Neblex with no file or network access; a script over SSH runs on your own server, usually through an On-Prem Worker, with installed packages, files and the host's permissions
Code steps and modules stay sandboxed; a script that needs packages or files runs over SSH on a server you control. Diagram by Neblex.

The first is a WebAssembly module, described above: compiled logic you reuse across flows and AI agents, still sandboxed.

The second is a script on a server you control, run over the SSH connector. The connector runs a command, or a Bash, shell, Python, or PowerShell script, on that host, usually through an On-Prem Worker inside your network. There, the script has whatever the host has: installed packages, files, and other programs.

I tested this against a Linux test server. A flow ran a Python script over SSH that imported the requests package, read a system file, ran a shell command, and wrote its result to a file, all things a Code step refuses to do. The script runs with that host's permissions, so set it up like any other server job: a dedicated user with only the access the script needs.

Moving code steps from another platform

When I help customers move code, these are the changes we make:

  • Check whether a built-in step does the job. Often one does, and the script goes away.
  • Wrap the logic in transform(item) or transform(items), take inputs from the record, and return the record.
  • Move API calls out of the script and into connector steps before or after it.
  • Replace packages with the standard library, or move that logic into a WebAssembly module.
  • If logic is copied into several flows, move it into a Rhai Transform Module or a WebAssembly module so there is one copy to fix.

For the rare script that needs packages or access to a server, run it over SSH on your own host instead, as described above.

What we found moving 31 scripts

The first question is the same as above: does this step need to be code at all? Of the 31 scripts we moved, 17 became built-in steps, 8 ran unchanged with only transform added, and 6 needed one change. Each of those six changes involved something outside the script's logic, such as an API call, an npm package, stored state, random IDs, or SQL built from strings.

Larger workflows follow the same pattern. We rebuilt two workflows from another automation platform's public template library whose logic lived in JavaScript code steps. A paginated API import of 11 steps, 3 of them code, became 5 steps with no code, using the HTTP step's built-in paging and retry settings.

The original's retry setting was never used, so one failed page silently cut the import short. A data-quality scoring job became Edit text, Remove duplicates, Filter, and Group & summarize steps, with SQL only to read and write rows and for one statistics query. Neither rebuild needed a code step.

What can go wrong

  • Money calculated in JavaScript can be off by a fraction of a cent. Use integer cents, or Python's decimal.
  • Returning null or None drops a record without an error. Compare the record count before and after the step when you test it.
  • A script that worked in a tool with network access may have hidden API calls. Search for fetch, requests, and http before you move it.
  • Long scripts copied between flows drift apart. Move shared rules into a module.
  • Normalize puts email addresses in standard form but keeps the part before the @ as written, which the email standard allows. For a duplicate check that ignores case, add an Edit text step that lowercases the address before Remove duplicates.

The takeaway

Start with the built-in steps, wherever possible. When you do need code, choosing between a Python or JavaScript code step comes down to who maintains it and what the job needs: JavaScript for reshaping records and Node-based code, Python for exact math and its standard library, Rhai for reusable rules, and WebAssembly for modules shared by flows and agents. All of them run sandboxed in Neblex, so pick for the people and the job, keep I/O in connector steps, and run a script that needs more than the sandbox allows over SSH on a server you control.

Sources

Last checked: November 30, 2026.

Frequently asked questions

Should I use Python or JavaScript in a workflow code step?

First check whether a built-in step does the job, because much of what needs a script in other tools doesn't in Neblex. If you need code, use the language your team reads most easily: JavaScript for reshaping JSON records and code moved from Node-based tools, Python for exact money math, statistics, and text checks, with decimal, statistics, and re in its standard library. For small rules you want to reuse across flows, use Rhai.

Can a code step call an API or read a file?

Not in Neblex: JavaScript, Python, and Rhai Code steps run in a sandbox with no file, network, or process access and no environment variables. They work only on the records the step receives. Calls to other systems go in connector steps, which use the connections you set up in Neblex.

Can I use pip or npm packages in a Neblex code step?

No. Python Code steps have the Python 3.11 standard library, without its modules for files, the network and processes, and JavaScript Code steps have the language itself, with no require or npm packages. For logic that needs a library, build a WebAssembly module, or run a script over the SSH connector on your own server.

Will my code from another automation tool run in Neblex?

Most transformation logic ports with small changes: wrap it in a transform function, take inputs from the record, and return the record. Code that calls APIs or imports packages needs to change, so move the API calls into connector steps. When we moved 31 scripts in our test, 8 ran unchanged, 6 needed one change like this, and 17 were replaced with built-in steps.

Talk to the people who build it

Bring us the product or the integration that hurts most

We will build it with you, on your data, with the run log open.