Getting started overview
Judge0 CE (Code Execution) is a self-hosted open-source online code execution system. It allows developers to run and test code snippets in a secure, isolated environment, making it suitable for applications like competitive programming platforms, online coding assessments, and interactive tutorials. Unlike the managed Judge0 API, Judge0 CE requires manual deployment and configuration on a user's infrastructure.
This guide outlines the essential steps to get Judge0 CE operational, from initial setup to making your first code execution request. The process involves deploying the Judge0 CE application, configuring its environment, and then interacting with its RESTful API. For detailed technical specifications, refer to the Judge0 official documentation.
Quick Reference Steps
The following table provides a high-level overview of the getting started process:
| Step | What to Do | Where |
|---|---|---|
| 1. Choose Deployment Method | Select a deployment strategy (e.g., Docker, Kubernetes, bare metal). | Judge0 CE Installation Guide |
| 2. Deploy Judge0 CE | Follow the chosen method to install Judge0 CE on your server. | Your server environment |
| 3. Configure Environment | Set up necessary environment variables and dependencies. | Server configuration files |
| 4. Verify Installation | Ensure Judge0 CE is running and accessible. | Local server access or browser |
| 5. Make First Request | Send a sample code execution request to the API. | cURL, Postman, or custom client |
Create an account and get keys
Judge0 CE is a self-hosted solution, which means there is no central account creation process or API key management provided by Judge0 itself. Instead, you deploy and manage the instance on your own infrastructure. Access control and authentication mechanisms are implemented at the infrastructure level or within your application that integrates with Judge0 CE.
For deployment, you will typically need access to a server or cloud environment. Common deployment methods include using Docker for containerization, which simplifies the setup process by packaging Judge0 CE and its dependencies into isolated containers. Users manage their own server credentials and access tokens for their chosen hosting provider, such as AWS, Google Cloud, or Azure.
Once Judge0 CE is deployed, access to its API endpoints is generally controlled by network configurations (e.g., firewalls, reverse proxies) and potentially application-level authentication if you build a wrapper around it. Judge0 CE itself does not generate API keys for its self-hosted version; access is direct to the deployed instance.
Your first request
After successfully deploying Judge0 CE, you can make your first code execution request. This involves sending a POST request to the /submissions endpoint with the code, language ID, and other parameters. The response will provide a token that can be used to retrieve the execution results.
Prerequisites
- A running Judge0 CE instance, accessible via an IP address or domain name (e.g.,
http://localhost:2358if running locally). - A tool for making HTTP requests, such as
cURL, Postman, or a programming language's HTTP client.
Example: Execute Python Code
This example demonstrates how to submit a simple Python script for execution and retrieve its output. The Python language ID for Judge0 is typically 71, but you can verify available language IDs by querying the /languages endpoint of your Judge0 CE instance.
Step 1: Submit the code
Send a POST request to the /submissions?base64_encoded=true&wait=true endpoint. The wait=true parameter tells Judge0 CE to wait for the submission to be processed and return the result directly, rather than providing a token for subsequent polling.
Request URL: http://YOUR_JUDGE0_CE_IP:2358/submissions?base64_encoded=true&wait=true
Request Method: POST
Request Headers:
Content-Type: application/json
Request Body:
{
"language_id": 71, // Python 3
"source_code": "cHJpbnQoXCJIZWxsbywgSnVkZ2UwIENFXCIp", // Base64 encoded 'print("Hello, Judge0 CE")'
"stdin": "",
"expected_output": ""
}
To base64 encode your source code, you can use online tools or programming language functions. For example, in Python: base64.b64encode(b'print("Hello, Judge0 CE")').decode('utf-8') results in cHJpbnQoXCJIZWxsbywgSnVkZ2UwIENFXCIp.
Step 2: Interpret the response
If wait=true was used, the response will contain the execution results directly. A successful response will have a status code of 200 OK and a JSON body similar to this:
{
"stdout": "Hello, Judge0 CE\n",
"time": "0.003",
"memory": 1736,
"stderr": null,
"compile_output": null,
"message": null,
"status": {
"id": 3, // Accepted
"description": "Accepted"
},
"language": {
"id": 71,
"name": "Python 3"
},
"source_code": "cHJpbnQoXCJIZWxsbywgSnVkZ2UwIENFXCIp",
"stdin": "",
"expected_output": "",
"token": "some-unique-token"
}
stdout: The standard output from the executed code.status.idandstatus.description: Indicate the execution result (e.g., Accepted, Time Limit Exceeded, Compilation Error).timeandmemory: Resources consumed by the execution.
If you omit wait=true, the initial response will only contain a token. You would then need to make a GET request to /submissions/{token} to retrieve the results once processing is complete. For example, http://YOUR_JUDGE0_CE_IP:2358/submissions/some-unique-token.
Common next steps
Once you have Judge0 CE running and have successfully executed your first code snippet, consider these common next steps to integrate it further into your application:
-
Integrate with a Frontend/Backend Application: Connect Judge0 CE to your web application's frontend for user input and display of results, or integrate it with your backend services for automated grading or testing. You can use any programming language that supports HTTP requests, such as Python with the
requestslibrary or JavaScript withfetchoraxios. - Configure Security and Isolation: Review and enhance the security of your Judge0 CE deployment. This may involve setting up appropriate firewall rules, configuring a reverse proxy (like Nginx or Apache) for SSL/TLS encryption, and ensuring the execution environment is isolated to prevent malicious code from affecting your host system. The Judge0 security documentation provides guidance on these aspects.
- Monitor and Scale: Implement monitoring for your Judge0 CE instance to track performance, resource usage, and potential errors. Depending on your expected load, you might need to scale your deployment by running multiple Judge0 CE instances and distributing requests using a load balancer.
- Explore Advanced Features: Judge0 CE supports various advanced features, including custom test cases, different compilers/interpreters, and resource limits. Explore the Judge0 API reference to understand all available parameters and functionalities for more complex use cases.
- Update and Maintain: Regularly check for updates to Judge0 CE to benefit from new features, performance improvements, and security patches. Establish a maintenance routine for your self-hosted instance.
Troubleshooting the first call
Encountering issues during the initial setup or first API call is common. Here are some troubleshooting tips for Judge0 CE:
-
Check Judge0 CE Service Status: Ensure that the Judge0 CE service is running on your server. If you deployed with Docker, use
docker psto see if the containers are active. For systemd services, usesudo systemctl status judge0(or similar, depending on your setup). -
Verify Network Accessibility: Confirm that your Judge0 CE instance is accessible from where you are making the API call. Check firewall rules on your server and network security groups if deployed in a cloud environment. The default port for Judge0 CE is
2358, so ensure it's open if necessary. -
Review Request Body and Headers: Double-check the JSON payload for correct syntax and required parameters (
language_id,source_code). Ensure theContent-Type: application/jsonheader is set correctly. Incorrect base64 encoding of thesource_codecan also lead to errors. -
Language ID Mismatch: If you receive an error related to an unsupported language, verify the
language_id. You can retrieve a list of supported languages and their IDs by making a GET request to the/languagesendpoint of your Judge0 CE instance. -
Check Server Logs: Access the logs of your Judge0 CE instance. If running in Docker, use
docker logs <container_id>. These logs often provide specific error messages that can help diagnose the problem, such as issues with compilers, interpreters, or resource limits. - Resource Constraints: If submissions are timing out or failing with memory errors, your server might be running low on resources (CPU, RAM). Monitor your server's resource usage and consider increasing allocated resources if the issue persists. The Google Cloud documentation on regions and zones offers general guidance on resource allocation in cloud environments, which can be applicable to self-hosted deployments.
- Consult Documentation and Community: If you're still stuck, refer to the comprehensive Judge0 documentation. The Judge0 community forums or GitHub issues might also have solutions for common problems.