Skip to main content

Code

Type ID: core.code  ·  Kind: Action  ·  Trace: CHAIN

Runs user-supplied code whose default export is a function. The function receives an args object and its return value becomes the node output. Currently only the JavaScript runtime is wired up.

Credentials

None

Properties

PropertyKeyTypeRequiredDefaultPossible valuesShown when
CodecodestringYesexport default async function main(args) { return { hello: "world", args }; }Source with a default-export functionAlways
Code TypecodeTypeoptionsNojsjs — javascript; py — pythonAlways
Custom ParameterscodeParamsobjectNo{}Key/value object, accessed via args.{paramValue} in the codeAlways
Global ParametersglobalParamsobjectNo{}Key/value object, injected as globals and accessed via {paramValue} directlyAlways

Notes

  • Runtime/language: although codeType offers js and py, the node always resolves the js runtime (// for now default is js); Python is not executed.
  • Execution happens in a Node.js worker_thread (js-runner). User code runs inside a vm context with a 5000 ms script-compile timeout. The optional execute-level timeoutMs is currently commented out in the node, so no outer kill-timer is applied.
  • Bindings available to user code: module, exports, require, a captured console (log/error/warn are recorded and echoed with a [user] prefix), and every key of globalParams spread into the sandbox as a global. args is passed as the function's first argument and is populated from codeParams.
  • require is reachable, and the runner declares an ALLOWED_MODULES set of axios and crypto (note: this set is declared but not enforced in the current code).
  • The code is transformed by replacing the first export default with module.exports =, then wrapped as (function (exports, require, module) { ... }). The default export (or module.exports) is taken; if it is a function it is called with args and awaited if it returns a thenable, otherwise the value itself is used as the result.
  • Output shaping: if the user result is a plain object containing a json and/or binary key, the node emits { __kind: 'json', json: <result.json|{}> , binary?: <normalized binary> }. Binary entries are validated to require base64 data and mimeType (missing either throws); fileSize defaults to the decoded byte length. Otherwise the entire result object ({ result, logs }) is emitted under json.
  • Errors thrown by user code propagate as an Error carrying the original message, stack, and captured logs; a non-zero worker exit code rejects with User code worker exited with code <n>.