Code Execution
Nodes for executing custom code within workflows.
Code execution nodes allow you to run custom JavaScript or Python code within your workflows for complex data transformations, custom logic, or integration with external libraries.
Available Nodes
| Node | Description | Documentation |
|---|---|---|
| JavaScript | Execute ECMAScript 5.1 compatible JavaScript code in secure sandbox | JavaScript Node → |
| Python | Execute Python 3.x code code in secure sandbox | Python Node → |
Quick Start
JavaScript Node
Execute JavaScript code with access to built-in functions and workflow context:
// Access workflow context - full access to nodes, vars, consts, and user data
var items = ctx.vars.items || [];
var userRole = ctx.user.roles[0] || 'user';
var previousResult = ctx.nodes.dataProcessor.outputs.data || {};
var total = 0;
// Process data (ES5.1 compatible)
for (var i = 0; i < items.length; i++) {
if (items[i] && items[i].value) {
total += items[i].value;
}
}
// Return result (automatically stored in workflow context)
return {
total: total,
count: items.length,
processedBy: ctx.user.login,
workspace: ctx.workspace_slug
};Key Features:
- ECMAScript 5.1 JavaScript sandbox
- Built-in crypto, random, and conversion utilities
- Full workflow context access via
ctxobject (see context docs) - Secure sandboxed execution
→ Learn more about JavaScript nodes
Python Node
Execute Python code with support for external libraries and complex data processing:
# Access full workflow context - nodes, vars, consts, user, and system data
items = args.get('vars', {}).get('items', [])
user_role = args.get('user', {}).get('roles', ['user'])[0]
previous_data = args.get('nodes', {}).get('dataProcessor', {}).get('outputs', {}).get('data', {})
workspace_name = args.get('workspace_slug', 'unknown')
# Process data
processed = []
for item in items:
if item.get('active'):
processed.append({
'id': item['id'],
'processed_value': item.get('value', 0) * 2,
'processed_by': args.get('user', {}).get('login', 'system')
})
# Return result (automatically stored in workflow context)
result = {
'processed': processed,
'count': len(processed),
'workspace': workspace_name,
'processor_role': user_role
}Key Features:
- Full Python 3.x runtime with built-in libraries
- Full workflow context access via
argsvariable (see context docs) - Comprehensive data processing capabilities
→ Learn more about Python nodes
Architecture Overview
JavaScript Nodes
- Runtime: ECMAScript 5.1 JavaScript sandbox
- Execution: Direct in-process with worker pool
- Security: VM sandboxing
- Libraries: Built-in utilities only
Python Nodes
- Runtime: Python 3.x sandbox environment
- Execution: Isolated sandbox execution
- Security: Container isolation
- Libraries: Python standard library built-in
Common Use Cases
| Use Case | Recommended Node | Why |
|---|---|---|
| Simple data transformation | JavaScript | Fast, built-in utilities |
| Complex calculations | Python | Math/statistics libraries, better numerics |
| API integrations | JavaScript | Built-in HTTP utilities |
| Advanced data processing | Python | Collections, itertools, statistics |
| String/XML processing | JavaScript | Built-in conversion utilities |
| Large dataset processing | Python | Memory efficient, built-in data structures |
Best Practices
Universal Guidelines
- Validate inputs - Check for required data and proper types
- Handle errors gracefully - Use appropriate error handling patterns
- Use workflow variables - Access shared data via context
- Return structured data - Use objects/dictionaries for results
- Keep code focused - Single responsibility per node
Language-Specific
- JavaScript: Use only ES5.1 syntax, leverage built-in utilities
- Python: Use standard library efficiently, leverage built-in data structures
Workflow Context Access
Both JavaScript and Python nodes have full access to the workflow execution context. For comprehensive documentation, see Workflow Context.
JavaScript:
// Access node outputs, variables, constants, user info, and system data
var nodeData = ctx.nodes.apiCall.outputs.result;
var variables = ctx.vars.userData;
var constants = ctx.consts.API_ENDPOINT;
var userInfo = ctx.user.login;
var workspace = ctx.workspace_slug;Python:
# Access complete workflow context via args variable
node_data = args.get('nodes', {}).get('apiCall', {}).get('outputs', {}).get('result')
variables = args.get('vars', {}).get('userData')
constants = args.get('consts', {}).get('API_ENDPOINT')
user_info = args.get('user', {}).get('login')
workspace = args.get('workspace_slug')Getting Started
- Choose your language based on your use case and requirements
- Read the specific documentation for your chosen node type
- Review best practices for robust, maintainable code
- Test with simple examples before building complex logic
JavaScript Node Documentation →
Python Node Documentation →
Best Practices →