Skip to main content
The Code node executes custom Python or JavaScript to handle complex data transformations, calculations, and logic within your workflow. Use it when preset nodes aren’t sufficient for your specific processing needs.
Code Node Configuration Interface

Code Node Configuration Interface

Code nodes need SANDBOX_ENABLE_NETWORK set to true, the default. If it’s false, every Code node fails with network is disabled, please enable it in the configuration.

Configuration

Define Input Variables to access data from other nodes in your workflow, then reference these variables in your code. Your function must return a dictionary containing the Output Variables you’ve declared.

Language Support

Choose between Python and JavaScript based on your needs and familiarity. Both languages run in secure sandboxes with access to common libraries for data processing.
Python includes standard libraries like json, math, datetime, and re. Ideal for data analysis, mathematical operations, and text processing.

Error Handling and Retries

Configure automatic retry behavior for failed code executions and define fallback strategies when code encounters errors.
Error Handling Configuration Options

Error Handling Configuration Options

Retry on failure allows up to 10 automatic retries with configurable intervals (maximum 5000ms). Enable this for handling temporary processing issues. Error Handling lets you define fallback paths when code execution fails, allowing your workflow to continue running even when the code encounters problems.
Retry Configuration Interface

Retry Configuration Interface

Output Limits

An output that exceeds any of these limits fails the node: With the default, an object output can hold three more levels of nested objects: the node’s outputs count as the first level, and arrays don’t add one. If a result exceeds a limit, reduce the output or raise the limit.

Security Considerations

Code in the sandbox can still reach other services inside your Dify deployment, so only run code you trust. To run code you don’t, ask your deployment administrator to isolate the sandbox’s network first.

Dependencies Support

Code nodes support external dependencies for both Python and JavaScript:
Dependencies are pre-installed in the sandbox environment. Check the available packages list in your Dify installation.
Last modified on November 11, 2026