Actions2
Overview
The "Run Code" operation of the YepCode node allows users to execute custom JavaScript or Python code dynamically within an n8n workflow. This code runs in a secure, sandboxed cloud environment with automatic support for any required NPM or PyPI packages, enabling complex logic, data transformation, or integration tasks without needing external servers or infrastructure.
Common scenarios include:
- Running quick scripts to manipulate input data on the fly.
- Executing dynamic business logic that changes per workflow run.
- Integrating with APIs or services by importing necessary libraries at runtime.
- Using AI-generated code snippets safely within workflows.
For example, you could write JavaScript code that adds timestamps to each input item or call external APIs using imported HTTP client libraries, all directly inside your workflow.
Properties
| Name | Meaning |
|---|---|
| Mode | Determines how the code executes relative to input items: • Run Once for All Items: Executes the code a single time regardless of the number of input items. • Run Once for Each Item: Executes the code separately for each input item. |
| Code | The source code to execute. Can be JavaScript or Python. Supports importing any NPM or PyPI package automatically. |
| Show Advanced Options | Toggles visibility of advanced configuration options. |
| Add n8n Context as Parameters | When enabled, injects the n8n context into the execution environment, providing access to input items and workflow metadata via yepcode.context.parameters.n8n. |
| Language | Specifies the language of the source code. Options are Auto (default), JavaScript, or Python. If Auto is selected, the system attempts to detect the language automatically. |
| Remove on Done | If enabled, removes the source code after execution; otherwise, keeps it. |
| Initiated By | A meta attribute to identify who initiated the execution (for tracking or logging purposes). |
| Comment | A meta attribute to add comments to the execution (for documentation or audit trails). |
Output
The output is an array of JSON objects representing the processed items after running the user-provided code. Each output item typically contains the original input item's JSON data merged or transformed according to the executed script's logic.
If binary data is produced by the code, it would be included in the output accordingly, but this operation primarily focuses on JSON data manipulation.
Dependencies
- Requires an API key credential for authentication with the YepCode service.
- The node relies on the YepCode cloud environment to run the code securely.
- Supports automatic installation of any NPM (for JavaScript) or PyPI (for Python) packages imported in the code.
- No additional local setup is needed; all dependencies are handled transparently by the YepCode platform.
Troubleshooting
Common Issues:
- Syntax errors or runtime exceptions in the provided code will cause execution failures.
- Incorrectly specifying the language may lead to parsing errors; use "Auto" or explicitly set the correct language.
- Forgetting to enable "Add n8n Context as Parameters" when accessing workflow data can result in undefined variables.
- Large or infinite loops in code can cause timeouts or resource exhaustion.
Error Messages:
"The operation \"run_code\" is not supported!"— indicates an invalid operation parameter; ensure "Run Code" is selected.- Runtime errors from the user code will be reported with stack traces; review and fix the code accordingly.
- Authentication errors suggest missing or invalid API credentials.
Resolutions:
- Validate and test code snippets independently before embedding them.
- Use console logs within the code to debug (
console.log()). - Ensure proper API key configuration in n8n credentials.
- Limit resource-intensive operations or optimize code logic.
Links and References
- YepCode Documentation: https://yepcode.io/docs/yepcode-coding-rules
- n8n Metadata Reference: https://docs.n8n.io/code/builtin/n8n-metadata/
- YepCode Dependency Support: https://yepcode.io/docs/dependencies