Run code
Component | Type | Description | |
---|---|---|---|
Run Code | 🔀 action | run Javascript or Python code |
The Run Code component allows you to run a snippet of code as part of a workflow. You can pass in placeholders that can then be used as variables in the code, and then pass values generated by the code as placeholders into the next component.
Technical details​
Behind the scenes, the Run Code component runs on Amazon Web Services Lambda, and has the following technical details
- runs on either a node.js 16 environment or a python 3.9 environment
- execution time for the code cannot exceed 20 seconds
- total size of the code cannot exceed 50MB
- cannot save any files (does not have access to any storage)
- has access to the internet via the following libraries: axiosClient (node.js) and requestsClient (python)
- can use any secrets and credentials stored and configured in the credentials store page
- can run a specific set of libraries depending on the language.
Available libraries​
The libraries available to use in the Run Code component are limited to the ones listed below. DO NOT import any other libraries in your code as this may result in errors in the deployment or execution of your code.
javascript libraries​
Library | Description |
---|---|
moment.js | Comprehensive date/time manipulation and formatting library. Handles parsing, validating, manipulating, and formatting dates. |
validator | String validation and sanitization library. Validates emails, URLs, credit cards, and other common string formats. |
url | Node.js URL parsing and manipulation module. Handles URL parsing, formatting, and resolution. |
util | Core Node.js utility functions. Provides debugging, formatting, type checking, and other utility functions. |
lodash | Utility library providing functions for arrays, numbers, objects, strings. Includes operations like sorting, filtering, mapping, and deep cloning. |
uuid | Generates and validates Universally Unique Identifiers (UUIDs). Used for creating unique IDs across systems. |
numbro | Number formatting and manipulation library. Handles currency formatting, unit conversions, and number parsing across locales. |
axiosClient | A special wrapper of the axios library for usage within the run code component inside of Workflow86. Behaves the same as axios, a Node.js library for making HTTP requests. Supports GET, POST, PUT, DELETE, and other HTTP methods. |
python libraries​
Library | Description |
---|---|
dateutil | A powerful extension to Python's datetime module. Used for parsing dates, calculating date differences, handling timezones, and recurring dates. |
math | Python's standard mathematical functions library. Provides access to mathematical operations and constants like sqrt, sin, cos, pi, etc. |
json | Handles JSON data encoding and decoding. Essential for working with JSON formatted data, API responses, and data serialization. |
csv | Reads and writes CSV (Comma Separated Values) files. Used for parsing and generating spreadsheet-like data. |
uuid | Generates unique identifiers (UUIDs/GUIDs). Useful for creating unique IDs for records, sessions, or any entity requiring unique identification. |
pandas | Powerful data manipulation and analysis library. Provides DataFrame and Series objects for handling structured data, data cleaning, merging, and analysis. |
numpy | Fundamental package for scientific computing. Offers support for large multi-dimensional arrays, matrices, and high-level mathematical functions. |
tabulate | Creates formatted text tables. Used for pretty-printing tabular data in various formats (ASCII, HTML, LaTeX, etc.). |
beautifulsoup4 | Parses HTML and XML documents. Provides tools for extracting and manipulating data from web pages. |
requestsClient | A special wrapper of the requests library for usage within the run code component inside of Workflow86. Behaves the same as requests, a Python library for making HTTP requests. Supports GET, POST, PUT, DELETE, and other HTTP methods. |
Internet access​
To enable internet access in the Run Code, turn on the internet access switch:
DO NOT IMPORT requestsClient or axiosClient in your code
Once internet access is enabled, you can use the libraries listed above in your code without the need to import them in the code.
You can now use the following libraries in your code:
- axiosClient (node.js)
- requestsClient (python)
Both of these libraries have the same functionality as axios and requests libraries in javascript and python.
Getting started with Run Code​
Step 1: Write your code and map the outputs​
Write the code you want to run, with the output specified as a map.
For example:
// This is sample JavaScript code that outputs a 'Hello World' message along with the current timestamp
// The following lines are the logic of
let message = 'Hello World';
let now = new Date();
// The following lines return the output of the Run Code as two outputs that will be used in Step 2
return {
// Each key in this map will become a output placeholder name - in this case 'hellowWorld'
helloWorld: message,
// The value after the colon is a reference to a variable set above and provides the value of the placeholder
currentTimestamp: now
};
In order to access the outputs of a Run Code in downstream components you need to include them in the return statement.
Step 2: Configure the outputs​
The final step is to set the data types, and values you want to export as placeholders to downstream components. To do this, you will reference the key in the key value pair you created in Step 2. The example below shows how to configure the outputs from the code example above:
You may also use Number, List, and HTML data types for your outputs.
Step 4: Perform a test run​
Click the Test button to perform a test run of the code to make sure everything is working properly.
Debugging errors in your code​
The Run Code component will return error messages if it encounters issues when running the code.
The tables below show the main code errors you may encounter.
To troubleshoot code errors, you can try copying and pasting the code error into Workflow86 AI via a component edit action. Workflow86 AI should return a configuration with its attempt to address the code error.
Python​
- AssertionError: This error occurs when the statements in the assert function do not satisfy the condition. An example of an
AssertionError
is when an assertion fails intentionally:
# AssertionError
assert False, "This assertion failed intentionally."
- AttributeError: This error occurs when a non-existent attribute has been called. An example of an
AttributeError
is attempting to access an attribute that does not exist:
# AttributeError
class MyClass:
pass
obj = MyClass()
print(obj.nonexistent_attribute)
- FloatingPointError: This error occurs when there is a calculation error that involves floats. An example of a
FloatingPointError
is dividing a float by zero:
# FloatingPointError
result = 1.0 / 0.0
- ImportError: This error occurs when you try to import a non-existent module. An example of an
ImportError
is attempting to import a module that does not exist:
# ImportError
import nonexistent_module
- IndentationError: This error occurs when there is an indentation that doesn’t satisfy Python’s syntax standards. An example of an
IndentationError
is incorrect indentation:
# IndentationError
def func():
print("Indented correctly")
print("This will raise IndentationError")
- IndexError: This error occurs when you try to reference an index that is out of bounds or does not exist. An example of an
IndexError
is accessing an index that is not present in the list:
# IndexError
my_list = [1, 2, 3]
print(my_list[5])
- KeyError: This error occurs when you try to call a key in a dictionary that doesn’t exist. An example of a
KeyError
is attempting to access a non-existent key in a dictionary:
# KeyError
my_dict = {"key": "value"}
print(my_dict["nonexistent_key"])
- MemoryError: This error occurs when the program runs out of memory. An example of a
MemoryError
is trying to create a list that is too large:
# MemoryError
big_list = [0] * 10**10
- NameError: This error occurs when a non-existent variable has been called. An example of a
NameError
is attempting to print a variable that has not been defined:
# NameError
print(nonexistent_variable)
- OverflowError: This error occurs when a calculation is done on numbers that are too big. An example of an
OverflowError
is performing an operation that results in a number larger than what is supported:
# OverflowError
result = 2 ** 1000
- SyntaxError: This error occurs when there are any syntax errors. An example of a
SyntaxError
is missing a parenthesis:
# SyntaxError
print("hello world"
- ZeroDivisionError: This error occurs when you try to divide a number by 0. An example of a
ZeroDivisionError
is dividing any number by zero:
# ZeroDivisionError
result = 1 / 0
Node.js​
- RangeError: This error is thrown when the index is out of bounds or non-existent. An example of a
RangeError
is when you try to create an array with a negative length:
// RangeError
var arr = new Array(-1);
- ReferenceError: This error occurs when the variable you are trying to reference does not exist. For instance, trying to log a non-existent variable to the console will throw a
ReferenceError
:
// ReferenceError
console.log(nonexistentVariable);
- SyntaxError: This error is thrown when there are any syntax errors. An example of a
SyntaxError
is missing a closing parenthesis in aneval
statement:
// SyntaxError
eval("alert('Hello, world!'"
- TypeError: This error is thrown when you run a function that is incompatible with the variable you are running from. For example, attempting to call
toUpperCase
on a number will result in aTypeError
:
// TypeError
var x = 1;
x.toUpperCase();
- URIError: This error is thrown when you use illegal characters in a URI function. An example of a
URIError
can be seen when trying to decode a standalone percent symbol in a URI, which is not valid:
// URIError
try {
decodeURI("%");
} catch (error) {
if (error instanceof URIError) {
console.error("URIError occurred: " + error.message);
}
}
Instructions for AI​
If you are using an external AI product or service to generate code such as ChatGPT, use the following instructions in your request or prompt to generate code that can be run inside of this component.
- Choose javascript (node.js 16) or python (python 3.9) based on best fit to execute the requirements or instructions.
- placeholders must be referenced with \$\{}.
- do not wrap placeholders in the code with single or double quotes.
- Return javascript or python objects depending on the selected language.
- Map the output values or variables from the source code to output placeholders in an object in this format: return { <outputPlaceholder1>: <variable2>, <outputPlaceholder2>: <variable2> }