PulbotDocumentation

Code tool


Runs JavaScript or Python code in a secure Pulbot sandbox. For logic that doesn't cleanly fit any other tool type: complex algorithms, proprietary format parsing, financial calculations, array manipulation.

When to use it

When you need logic that no other tool type can express cleanly.

Steps

  1. 1Create a tool → choose type «Code».
  2. 2Select the language: JavaScript or Python.
  3. 3Write the code. Flow variables are injected as a global context object: access with context.variable_name.
  4. 4The code must return a value (return in JS, or the last evaluated expression in Python).
  5. 5Save and test with a sample context.

Reference

context
Object with all flow variables available at that point. E.g. context.message, context.user_id.
return
The returned value is available in downstream nodes as the node's output.
Available libraries (JS)
Native Node.js modules (crypto, path, url). External npm imports are not allowed.
Available libraries (Python)
json, math, re, datetime, collections, itertools. External pip imports are not allowed.
Timeout
Code has an execution time limit. Very slow operations are aborted.

Common errors

«SyntaxError»
Syntax error in the code. Check the test console for the exact line number.
«context.X is undefined»
Variable X doesn't exist in the flow at that point. Check the name and that the node generating it comes before this one.
Execution timeout
The code took longer than the limit. Optimize loops or remove blocking operations (no async I/O available).

Next step

Learn to test any tool before using it in a flow.

¿Necesitas ayuda?