Execute Code icon

Execute Code

Execute code using Judge0 API

Overview

This node allows users to execute multiple blocks of source code in various programming languages using the Judge0 API, a popular online code execution and evaluation service. It is particularly useful for educational platforms, coding challenge systems, or automated testing environments where you want to programmatically run and evaluate code submissions.

Typical use cases include:

  • Automatically running student code submissions and retrieving their output, execution time, and memory usage.
  • Testing snippets of code in different languages without setting up local compilers or runtimes.
  • Integrating code execution into workflows that require dynamic code evaluation with input data.

For example, a teacher could submit several code blocks written by students, specify the language, and receive detailed feedback on each submission's output and performance metrics.

Properties

Name Meaning
IdStudent Unique identifier to distinguish each student's code submission.
Language Code Programming language of the submitted code. Supported options include "C", "C++", "Java", and others (mapped internally to Judge0 language IDs).
Delay Time Delay in milliseconds between consecutive code submissions to the Judge0 API (range: 1000 to 10000 ms). This helps avoid rate limiting or overloading the API.
Additional Code A collection of one or more code blocks to execute. Each block includes:
- Your Code: The source code string to be executed.
- Input for Code: Optional input string to be passed as standard input during execution.

Output

The node outputs an array of JSON objects, each representing the results of executing the submitted code blocks for a particular student ID. Each object contains:

  • MSSV: The student ID provided as input.
  • For each code block submitted, three fields are added:
    • stdout_BaiX: The standard output from the code execution of block X, decoded from base64 to UTF-8. If there was a compilation error or no code was provided, this field contains an appropriate message ("Compilation error" or "Code empty").
    • time_BaiX: The execution time reported by Judge0 for block X.
    • memory_BaiX: The memory usage reported by Judge0 for block X.

If an error occurs during the request to the Judge0 API, the corresponding stdout_BaiX field will contain an error message describing the failure.

The node does not output binary data.

Dependencies

  • Requires access to the Judge0 API via RapidAPI.
  • An API key credential for authenticating requests to the Judge0 API must be configured in n8n.
  • Network connectivity to https://judge0-ce.p.rapidapi.com is necessary.
  • The node uses base64 encoding to send source code and input securely to the API.

Troubleshooting

  • Common issues:

    • Rate limiting or too frequent requests: If the delay time between submissions is set too low, the Judge0 API may reject requests. Increase the "Delay Time" property to at least 1000 ms.
    • Invalid language code: Using a language not mapped internally to Judge0 language IDs will cause errors or unexpected behavior.
    • Empty code blocks: Submitting empty code strings results in "Code empty" messages in the output.
    • Compilation errors: If the submitted code fails to compile, the output will indicate "Compilation error".
    • API authentication errors: Ensure the API key credential is correctly set up and valid.
  • Error messages:

    • Errors thrown by the node typically originate from failed HTTP requests or invalid responses from the Judge0 API. The node surfaces these as error messages prefixed with "Error:" followed by the specific issue.
    • To resolve, verify API credentials, network access, and input correctness.

Links and References

Discussion