CodeLand Runner is a lightweight HTTP server designed to execute code snippets and return the results. It is primarily used in conjunction with the CodeLand Manager project for managing code execution on remote runners.
The CodeLand Runner provides a simple HTTP interface for executing code snippets and retrieving the results in a structured JSON format. It can be easily integrated into various systems that require remote code execution capabilities.
This repository contains the CodeLand Runner code, which is a part of the CodeLand Manager ecosystem.
To use the CodeLand Runner, you'll typically follow these steps:
-
Compile the Code: Compile the CodeLand Runner code using the provided build script or your preferred method. Ensure that all dependencies, including the cJSON library, are correctly set up.
-
Run the Server: Start the CodeLand Runner server on the desired host and port. By default, it listens on port 15000, but you can customize it by setting the
runnerPortenvironment variable. -
Send Requests: Use HTTP requests to send code snippets to the CodeLand Runner for execution. You can send POST requests with a JSON payload containing the code to be executed. The runner will execute the code and return the results.
-
Receive Results: Parse the JSON response from the CodeLand Runner to retrieve the execution results. The response includes a "res" field containing the base64-encoded output of the executed code.
Here's an example of sending a POST request to execute code with the CodeLand Runner using curl:
curl -X POST http://localhost:15000 -d '{"code": "echo \"Hello, CodeLand!\"" }'The response will be a JSON object with the execution result:
{
"res": "SGVsbG8sIENvZGVMYW5kIQo="
}On macOS, the runner can be installed as a boot-time LaunchDaemon — a system service that starts at boot, runs as root, and restarts automatically if it crashes.
| File | Purpose |
|---|---|
crunner.plist |
LaunchDaemon definition (com.codeland.crunner): start at boot, keep alive, log to /var/log/crunner.log |
install_service.sh |
Builds the binary, installs it to /usr/local/bin/crunner, installs the plist to /Library/LaunchDaemons/, and loads the service |
uninstall_service.sh |
Stops the service and removes the binary and plist |
./install_service.shThe script requires sudo. After it finishes, the runner is listening on port 15000 (or the runnerPort value set in the plist).
launchctl print system/com.codeland.crunner # service status (look for state = running)
curl -X POST http://localhost:15000 -d '{"code": "echo ok" }'
tail -f /var/log/crunner.log # logsA healthy response looks like:
{"res":"b2sK"}(b2sK is ok\n base64-encoded.)
sudo launchctl bootout system/com.codeland.crunner # stop (service stays installed)
sudo launchctl kickstart -k system/com.codeland.crunner # restart / reload config
./uninstall_service.sh # remove the service entirelyTo change the port, edit the runnerPort value in crunner.plist (and in /Library/LaunchDaemons/com.codeland.crunner.plist if already installed), then reload with sudo launchctl kickstart -k system/com.codeland.crunner.
plutil -lint crunner.plistvalidates the plist syntax.- If the service is stuck in
spawn scheduled/exitedstate, check/var/log/crunner.log— the most common cause is another process already bound to the port. launchctl print system/com.codeland.crunnerprintsBad request.when the service is not currently loaded.
Because the daemon runs as root, any code sent to the runner executes with root privileges. Keep the port closed to untrusted networks if the machine is exposed.
This project is licensed under the MIT License - see the LICENSE file for details.
- William Mantly (wmantly@gmail.com)
This README was generated with ❤️ by an AI language model.