Codewars.com code sandbox capabilities
This project is both a command-line utility and server, used by Codewars to execute small sets of code within various languages, using various testing frameworks.
You can run
node run --help to view information about which arguments are supported.
The purpose of this project is to provide a low level ability to run 'Kata'. It provides a mechanism for executing different configurations of code using various languages and testing frameworks.
Docker can be utilized in order to sandbox code execution. A server is provided that can accept 'run' requests and execute them within a Docker container.
The CLI capabilities can be used without having to run Docker. As long as you have the language and frameworks installed on your host machine, you will be able to run the CLI tool standalone.
If you just wanted to execute some code and return its output, you can do so like the following:
node run -l ruby -c 'puts 123'
node run -l js -c 'console.log(123)'
node run -l py -c 'print 123'
You can also provide a test fixture to be run along with the code. The output returned is the same output that is parsed by Codewars to render its kata output.
node run -l ruby -c 'a = 1' -f 'Test.expect a == 1'
node run -l js -c 'a = 1' -f 'Test.expect(a == 1)'
node run -l py -c 'a = 1' -f 'test.expect(a == 1)'
docker build -t codewars/cli-runner .
docker run --rm codewars/cli-runner --help
docker run --rm codewars/cli-runner run -l ruby -c 'a = 1' -f 'Test.expect a == 1'
docker run --rm codewars/cli-runner run -l js -c 'a = 1' -f 'Test.expect(a == 1)'
docker run --rm codewars/cli-runner run -l py -c 'a = 1' -f 'test.expect(a == 1)'
You can run a server which wraps the CLI and runs it within a Docker container. If you have Docker installed on your machine and the Codewars image built, all you need to do to start the server is run
node server. You can then make posts requests to
localhost:8080/run and provide the same arguments that you would for the CLI tool.
Version 1.6.3 or higher is required.
A fully working environment is provided via Vagrant. These steps will get a working server running:
vagrant upvagrant sshcd /vagrantnode buildsupervisor server.js
You should now have a fully working server with Docker support. You can access the server using
localhost:8080. You can post requests to
/run with the same arguments that the CLI accepts.
The Docker images used by server.js are tagged within a version number. Some utilities have been provided to make it easier to manage versioned images.
node build to build the latest versioned image
grab the files
cd /git clonecd /codewars-runner/setup
create a non-root user and give it permissions
provision the machine
set up the production environment
set up the hourly docker restart