header
login

Code Execution (code)

The code function lets you execute custom Python code in an isolated sandbox. Use it for data processing, calculations, and transformations that aren't possible with standard functions.

Parameters

Parameter Description
code Code to execute (Python)
save_as Variable name to store the result

Writing Code

Code is written in a built-in editor with Python syntax highlighting. Use return to output a result:

return input

If your code doesn't use return, you can assign the result to a result variable:

result = 42

Available Data

All variables created earlier in the workflow (via add_var, http_request, etc.) are accessible inside the code.

Available Functions

The sandbox provides a limited set of built-in functions. Module imports are not allowed.

Basics

int, float, str, bool, len, range, print

Math

abs, round, min, max, pow, sqrt, sin, cos, tan, log, exp

Random Numbers

random(), randint(a, b), uniform(a, b), choice(seq)

Time

time() — current time in seconds (Unix timestamp)

Examples

Text Processing

text = message.upper()
return text

Calculations

price = 100
discount = 0.15
return round(price * (1 - discount), 2)

Random Selection

responses = ["Yes", "No", "Maybe", "Ask later"]
return choice(responses)

Limitations

  • No importsimport, open, exec, eval, and other unsafe operations are forbidden
  • Timeout — execution is limited to 30 seconds
  • Code size — up to 500,000 characters
  • Result size — up to 2,000,000 characters
  • No access to the file system, network, or system resources

Saving the Result

The execution result (the return value or the result variable) is saved to the variable specified in save_as. It can then be used in subsequent functions:

Calculation result: {=result=}

Code Editor

Double-clicking the block opens a full-featured editor with:

  • Python syntax highlighting
  • Line numbers
  • Automatic word wrapping