code-racer

module
v0.0.0-...-4f4fead Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 25, 2023 License: MIT

README

Code Racer

A Remote Code Execution Engine built with Go and ❤️

GitHub last commit GitHub issues GitHub pull requests Tests

Setup

Create a .env file with the following:

VERSION=0.0.3
APP_NAME=thefl45h/code-racer

This is necessary for building the docker container and using the Makefile

Environment variables

  • PORT(optional): port to serve requests. Defaults to 8000

  • RUNNERS_PATH(required): Path to runners script. This should be an absolute path to the runners directory in the repo. This will be mounted in each executor

  • MNTFS(required): Path to mounted filesystem. Code racer will create directories and files for code execution. This should be an absolute path. This will be mounted in each executor. Recommend using an absolute path to the mntfs folder in this repo.

  • NOSOCKET(optional): Path to nosocket binary. This should be an absolute path. If this env variable is not set, set DISABLE_NETWORKING to 1.

  • PULL_IMAGES(optional): true/false. Attempt to pull images or not. May be useful of executor images are already available locally.

  • DISABLE_NETWORKING(optional): 1/0. If 1 running tasks will not be able to access the internet and make network calls. 0 running tasks/process will have access to the internet.

Running in development

Create an .env.development with the above environment variables. Refer to .env.sample Create an .devcontainer/.env with the environment variables in .devcontainer/.env.sample

We strongly recommend docker/docker-compose for a smooth development process.

This project includes a (devcontainer)[https://code.visualstudio.com/docs/devcontainers/containers].

In the dev container, you can use the air command to start up the server with hot reloading.

Running in production

Create an .env.production with the above environment variables. Refer to .env.sample

Use the root docker-compose.yml file to create a production ready docker image

Building docker image

docker-compose build

Starting container

docker-compose up

What is nosocket?

nosocket is a custom binary that uses libseccomp to block socket calls. This is a security measure to prevent tasks submitted from accessing the internet.

API Documentation

Swagger Docs

/api/v1/swagger

Public API

POST https://code-racer-api.codewithflash.com/api/v1/execute
GET https://code-racer-api.codewithflash.com/api/v1/runtimes

Runtimes endpoint

GET /api/v1/runtimes: Endpoint to list available runtimes

Response

[
    {
        "language": "python3"
    },
    {
        "language": "node"
    }
]

Execute endpoint

POST /api/v1/execute. Endpoint to execute code

  • language(required): language to use for execution. Refer to /api/v1/runtimes for available languages

  • entrypoint(required): the file path to start execution from. This path must be present in files

  • files(required): An array of files containing code to be used for execution.

  • file.name(required): filename

  • file.content(required): content of file

{
    "language": "node",
    "entrypoint": "main.js",
    "files": [
        {
            "name": "main.js",
            "content": "console.log('Code Racer')"
        }
    ]
}
{
    "stderr": "",
    "stdout": "Code Racer\n",
    "executionTime": "438.757875ms",
    "preparationTime": "102.106667ms"
}

Supported Languages

python, node, go, php, java, ruby

More to come

Directories

Path Synopsis
cmd
internal
api
cappedbuffer
Credit: https://github.com/ranna-go/ranna/blob/master/pkg/cappedbuffer/cappedbuffer.go
Credit: https://github.com/ranna-go/ranna/blob/master/pkg/cappedbuffer/cappedbuffer.go
doc
Package doc Code generated by swaggo/swag.
Package doc Code generated by swaggo/swag.
file_system
Purpose of this package is to create the request's files and folders
Purpose of this package is to create the request's files and folders
runtime_manager
this package manages containers available for execution
this package manages containers available for execution
pkg

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL