A fully free and open-source API that runs project-level (multi-file) code on both local machines and remote servers with sandboxes. It supports languages including Python JS/TS C/C++ Java Dafny Bash SQL etc.
OpenCodeRunner can be used in many ways:
- LLM, agent, reasoning, RL
- Project-level code evaluation
- Safe sandbox running
- Multi-language running
- Cloud or remote code running
- ...
# Install
git clone https://github.com/OpenCodeRunner/OpenCodeRunner
cd OpenCodeRunner
pip install -r requirements.txt
pip install -e .
# Uninstall
pip uninstall opencoderunner
bash ./uninstall.sh2. (Optional) Install Firejail sandbox for safety control (https://github.com/netblue30/firejail)
# Install via `apt`
sudo add-apt-repository ppa:deki/firejail
sudo apt-get update
sudo apt-get install firejail firejail-profiles
# Or install via building manually
git clone https://github.com/netblue30/firejail.git
cd firejail
./configure && make && sudo make install-strip3. The installation guides for each code language's environment is in install_envs.md
You can use firejail uvicorn to start the OpenCodeRunner service for remotely code execution. You can configure API key settings in .env for both client and server sides.
# Under the repo's root `OpenCodeRunner/` directory
firejail && bash start_server.sh
# Or if you don't have `firejail`
bash start_server.shThen you can use either run_on_local or run_on_server for code running.
If you use run_on_server, you need to specify host port api_key. You can configure API key settings in .env for both client and server sides.
- Code string running example.
from opencoderunner.run_info import RunInfo
from opencoderunner import run
if __name__ == "__main__":
run_info = RunInfo(
code_str="import sys; print(sys.stdin.read())",
language="python",
project_root_name="project_root_name",
input_content="INPUT1\nINPUT2\n",
timeout=1, # Test timeout
)
# # -- Run locally
for i in range(3):
result_info = run(run_info=run_info)
print(run_info.command)
print(result_info)
# -- Or Run on server
for i in range(3):
result_info = run(run_info=run_info,
host="0.0.0.0",
port=8000,
)
print(result_info)- Quick run bash command example.
from opencoderunner import RunInfo
from opencoderunner import run as opencr_run
if __name__ == "__main__":
run_info = RunInfo(
code_str="sleep 3",
language="bash",
timeout=2, # Test timeout
is_quick_run=True, # Test quick run
)
# -- Run locally
for i in range(3):
result_info = opencr_run(run_info=run_info)
print(run_info.command)
print(result_info)- Project-level example. It consists of multiple files.
from opencoderunner.run_info import RunInfo
from opencoderunner.file_info import FileInfo
from opencoderunner import run
if __name__ == "__main__":
run_info = RunInfo(
file_infos=[
FileInfo(
file_relpath="folder1/file1.py",
file_content="""
def main1():
import numpy as np
arr = np.array([1, 2, 3])
print("Hello World")
output = arr.sum()
return output
"""
),
FileInfo(
file_relpath="file2.py",
file_content="""
from folder1.file1 import main1
import sys
import json
print(main1())
for line in sys.stdin:
line = line.strip()
print(line)
"""
)
],
language="python",
project_root_name="project_root_name",
entry_file_relpath="file2.py",
input_content="INPUT1\nINPUT2\n",
)
run_info.print_tree()
# -- Run locally
for i in range(3):
result_info = run(run_info=run_info)
print(result_info)
# -- Or Run on server
for i in range(3):
result_info = run(run_info=run_info,
host="0.0.0.0",
port=8000,
)
print(result_info)You can configure the default paths for different languages in opencoderunner/infos/run_info.py. For example, python path, cmake path, java JDK path, node.js path, etc.
More examples for various code languages are in examples/. You can run them easily.
- Sandbox for permission control
- Project structure visualization
- Input/argparse/stdin
- PyPi/Conda
- API key
- Code str running (simple running)
- Merge local+server
- os.getcwd issue
- remove too much print
- Python
- JavaScript
- TypeScript
- C (CMake)
- C++ (CMake)
- Java
- Dafny
- Bash
- SQL
- ...
- [2025-04-17] Launch OpenCodeRunner
😊 We welcome passionate contributors! If you are interested, feel free to contact!
