Code Execution Node

vellum.workflows.nodes.CodeExecutionNode

Used to execute arbitrary Python code within your workflow. Supports custom package dependencies and any Python or TypeScript runtimes.

Important: Your code file must contain a main() function with parameters that match the names of the node’s inputs. Without this function, you’ll get a NameError: name 'main' is not defined error.

Attributes

filepath
strRequired

Path to the Python script file to execute

code_inputs
EntityInputsInterfaceRequired

The inputs for the custom script. Supports:

  • Strings
  • Numbers (float)
  • Arrays
  • Chat History (List[ChatMessage])
  • Search Results (List[SearchResult])
  • JSON objects (Dict[str, Any])
  • Function Calls
  • Errors
  • Secrets
runtime
CodeExecutionRuntimeDefaults to PYTHON_3_12

The runtime to use for the custom script

packages
Optional[Sequence[CodeExecutionPackage]]

The packages to use for the custom script

request_options
Optional[RequestOptions]

The request options to use for the custom script

Outputs

result
_OutputType

The result returned by the executed code, type depends on the node’s generic type parameter

log
str

The execution logs from the code run