Arbitrary code execution Discord bot
Find a file
2019-05-14 21:08:59 -04:00
docker Avoid filename conflicts and cleanup files after 2019-05-14 20:21:34 -04:00
src Add prepare option 2019-05-14 20:39:23 -04:00
.eslintrc.json Initial commit 2019-03-12 05:09:46 -04:00
.gitattributes Initial commit 2019-03-12 05:09:46 -04:00
.gitignore Initial commit 2019-03-12 05:09:46 -04:00
config.example.json Explain config options 2019-05-14 20:50:07 -04:00
CONTRIBUTING.md Add CONTRIBUTING.md 2019-03-12 12:01:07 -04:00
LICENSE Initial commit 2019-03-12 05:09:46 -04:00
package-lock.json Update dependencies 2019-05-14 21:08:44 -04:00
package.json Bump version 2019-05-14 21:08:59 -04:00
README.md More readme stuffs 2019-05-14 21:05:12 -04:00

Comp_iler

Sandboxed code execution discord bot.

Usage

Code Blocks

>```lang
code
```
>options```lang
code
```

Inline Code

>`lang code`
>options`lang code`

Examples

>```cpp
#include <iostream>

int main()
{
    std::cout << "Hello World!" << std::endl;
}
```
>harmony```js
class Foo {
    bar = 1;
}

console.log(new Foo().bar);
```
>`py print('hello world')`
>e`hs (+) <$> Just 1 <*> Just 2`

Supported Languages and Options

One of the following language codes is set in lang.
Options are optionally set in options, which is a semicolon-delimited list of flag or flag=value.

  • bash Bash
  • c C (GCC)
  • clj Clojure
  • cpp C++ (G++)
  • cs C# (Mono)
    • e evaluates a single expression instead of a module
  • elixir Elixir
  • fs F# (Mono)
  • go Go
  • hs Haskell (GHC)
    • e evaluates a single expression instead of a module
  • java Java (OpenJDK)
  • js JavaScript (Node)
    • harmony enables harmony features (--harmony on node)
    • e prints the result of evaluating the code
  • julia Julia
    • e prints the result of evaluating the code
  • lisp Racket
  • lua Lua
  • ocaml OCaml
  • pas Pascal (FPC)
  • php PHP
  • pl Perl5
  • prolog Prolog (SWI-Prolog)
  • py Python (CPython)
    • 2 runs Python 2 instead of Python 3
  • rb Ruby
  • rs Rust

How it Works

Read the source code, specifically src/struct/LanguageHandler.js.
In summary, for every language there is a docker image which spins up a docker container.
The container is used for all evaluations of code, restarting if something goes wrong.
The container is locked down, so there is no networking, limited memory and CPU usage, and a time limit.

Setup

  1. Install Docker 18+
  2. Install Node 10+
  3. Run npm i
  4. Fill out config.json
    • owner - The owner(s) of the bot.
      Use an array for multiple owners.
    • token - The bot token.
    • languages Languages to use.
      The language names here are different from the user-facing ones.
      Check the folders in ./docker/ for the language names.
      Change to null to enable all languages.
    • memory Max memory usage of a container.
    • cpu Max CPU usage of a container.
    • timeout Time limit for code in milliseconds.
    • prepare Whether to run containers on setup.
      Setting to true will speed up the first eval, but that language might not be used.
  5. Run node .