All Projects → engineer-man → Piston

engineer-man / Piston

Licence: mit
A high performance general purpose code execution engine.

Programming Languages

shell
77523 projects

Labels

Projects that are alternatives of or similar to Piston

harbour-containers
A Linux containers manager for SailfishOS
Stars: ✭ 30 (-95.44%)
Mutual labels:  lxc
Lxd
Powerful system container and virtual machine manager
Stars: ✭ 3,115 (+373.4%)
Mutual labels:  lxc
Vas Quod
🚡 Minimal linux container runtime.
Stars: ✭ 404 (-38.6%)
Mutual labels:  lxc
bakery
Simple tool to backup and restore ChromeOS Crostini containers
Stars: ✭ 18 (-97.26%)
Mutual labels:  lxc
cv4pve-botgram
Telegram Bot for Proxmox VE
Stars: ✭ 26 (-96.05%)
Mutual labels:  lxc
Cntr
A container debugging tool based on FUSE
Stars: ✭ 295 (-55.17%)
Mutual labels:  lxc
DockerAndKubernetes
Docker and Kubernetes cheat sheets and examples for familiarization. Also contains some documentation on LXC.
Stars: ✭ 31 (-95.29%)
Mutual labels:  lxc
Lxcfs
FUSE filesystem for LXC
Stars: ✭ 602 (-8.51%)
Mutual labels:  lxc
cbtool
Cloud Rapid Experimentation and Analysis Toolkit
Stars: ✭ 65 (-90.12%)
Mutual labels:  lxc
Lxdock
Build and orchestrate your development environments with LXD - a.k.a. Vagrant is Too Heavy™
Stars: ✭ 350 (-46.81%)
Mutual labels:  lxc
demo-container-runtime
Simple demonstration codebase for how containers work
Stars: ✭ 37 (-94.38%)
Mutual labels:  lxc
python2-lxc
Python 2.7 binding for liblxc (similar to the better supported python3-lxc)
Stars: ✭ 49 (-92.55%)
Mutual labels:  lxc
Lxc
LXC - Linux Containers
Stars: ✭ 3,583 (+444.53%)
Mutual labels:  lxc
ansible virtualization
Ansible Collection: Virtualization roles
Stars: ✭ 31 (-95.29%)
Mutual labels:  lxc
Lxdui
LXDUI is a web UI for the native Linux container technology LXD/LXC
Stars: ✭ 443 (-32.67%)
Mutual labels:  lxc
ProxmoxVE PHP API
ProxmoxVE PHP API
Stars: ✭ 78 (-88.15%)
Mutual labels:  lxc
Lxdmosaic
Web interface to manage multiple instance of lxd
Stars: ✭ 270 (-58.97%)
Mutual labels:  lxc
Amicontained
Container introspection tool. Find out what container runtime is being used as well as features available.
Stars: ✭ 638 (-3.04%)
Mutual labels:  lxc
Lxc Web Panel
LXC Web Panel repository
Stars: ✭ 555 (-15.65%)
Mutual labels:  lxc
Go Lxc
Go bindings for liblxc
Stars: ✭ 336 (-48.94%)
Mutual labels:  lxc

engineer-man piston Piston

A high performance general purpose code execution engine.


GitHub last commit GitHub issues GitHub pull requests


AboutPublic APIGetting StartedUsageSupported LanguagesPrinciplesSecurityLicense



About

Piston is a high performance general purpose code execution engine. It excels at running untrusted and possibly malicious code without fear from any harmful effects.


It's used in numerous places including:

To get it in your own server, go here: https://emkc.org/run.


Public API

  • Requires no installation and you can use it immediately.
  • Reference the Versions/Execute sections below to learn about the request and response formats.

When using the public Piston API, use the base URL:

https://emkc.org/api/v1/piston

GET

https://emkc.org/api/v1/piston/versions

POST

https://emkc.org/api/v1/piston/execute

Important Note: The Piston API is rate limited to 5 requests per second. If you have a need for more requests than that and it's for a good cause, please reach out to me (EngineerMan#0001) on Discord so we can discuss potentially getting you an unlimited key.


Getting Started

Host System Package Dependencies

  • NodeJS
  • lxc
  • libvirt

If your OS is not documented below, please open pull requests with the correct commands for your OS.

CentOS / RHEL
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.37.2/install.sh | bash
nvm install --lts
nvm use --lts

yum install -y epel-release
yum install -y lxc lxc-templates debootstrap libvirt
systemctl start libvirtd
Ubuntu (18.04)
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.37.2/install.sh | bash
nvm install --lts
nvm use --lts

apt install -y lxc lxc-templates debootstrap libvirt0
Arch Linux
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.37.2/install.sh | bash
nvm install --lts
nvm use --lts

pacman -S lxc libvirt unzip

After system dependencies are installed, clone this repository:

# clone and enter repo
git clone https://github.com/engineer-man/piston

Installation (simple)

  • Install additional dependencies python3, pip and distrobuilder
  • cd container && ./build.sh
  • Wait, it may take up to an hour.
  • lxc-create -n piston -t local -- --metadata meta.tar.xz --fstree rootfs.tar.xz
  • cd lxc && ./start
  • Good to go!

Installation (advanced)

  • See var/install.txt for how to build the container manually

CLI Usage

  • cli/execute [language] [file path] [args]

Usage

CLI

lxc/execute [language] [file path] [args]

API

To use the API, it must first be started. Please note that if root is required to access LXC then the API must also be running as root. To start the API, run the following:

cd api
./start

For your own local installation, the API is available at:

http://127.0.0.1:2000

Versions Endpoint

GET /versions This endpoint will return the supported languages along with the current version and aliases. To execute code for a particular language using the /execute endpoint, either the name or one of the aliases must be provided.

HTTP/1.1 200 OK
Content-Type: application/json

[
    {
        "name": "awk",
        "aliases": ["awk"],
        "version": "1.3.3"
    },
    {
        "name": "bash",
        "aliases": ["bash"],
        "version": "4.4.20"
    },
    {
        "name": "c",
        "aliases": ["c"],
        "version": "7.5.0"
    }
]

Execute Endpoint

POST /execute This endpoint requests execution of some arbitrary code.

  • language (required) The language to use for execution, must be a string and supported by Piston (see list below).
  • source (required) The source code to execute, must be a string.
  • stdin (optional) The text to pass as stdin to the program. Must be a string or left out of the request.
  • args (optional) The arguments to pass to the program. Must be an array or left out of the request.
{
    "language": "js",
    "source": "console.log(process.argv)",
    "stdin": "",
    "args": [
        "1",
        "2",
        "3"
    ]
}

A typical response upon successful execution will contain the language, version, output which is a combination of both stdout and stderr but in chronological order according to program output, as well as separate stdout and stderr.

HTTP/1.1 200 OK
Content-Type: application/json

{
    "ran": true,
    "language": "js",
    "version": "12.13.0",
    "output": "[ '/usr/bin/node',\n  '/tmp/code.code',\n  '1',\n  '2',\n  '3' ]",
    "stdout": "[ '/usr/bin/node',\n  '/tmp/code.code',\n  '1',\n  '2',\n  '3' ]",
    "stderr": ""
}

If a problem exists with the request, a 400 status code is returned and the reason in the message key.

HTTP/1.1 400 Bad Request
Content-Type: application/json

{
    "message": "Supplied language is not supported by Piston"
}

Supported Languages

awk, bash, brainfuck, c, cpp, clojure, crystal, csharp, d, dash, deno, elixir, emacs, elisp, go, haskell, java, jelly, julia, kotlin, lisp, lolcode, lua, nasm, nasm64, nim, node, osabie, paradoc, perl, php, python2, python3, ruby, rust, scala, swift, typescript, zig,


Principle of Operation

Piston utilizes LXC as the primary mechanism for sandboxing. There is a small API written in Node which takes in execution requests and executes them in the container. High level, the API writes a temporary source and args file to /tmp and that gets mounted read-only along with the execution scripts into the container. The source file is either ran or compiled and ran (in the case of languages like c, c++, c#, go, etc.).


Security

LXC provides a great deal of security out of the box in that it's separate from the system. Piston takes additional steps to make it resistant to various privilege escalation, denial-of-service, and resource saturation threats. These steps include:

  • Disabling outgoing network interaction
  • Capping max processes at 64 (resists :(){ :|: &}:;, while True: os.fork(), etc.)
  • Capping max files at 2048 (resists various file based attacks)
  • Mounting all resources read-only (resists sudo rm -rf --no-preserve-root /)
  • Cleaning up all temp space after each execution (resists out of drive space attacks)
  • Running as a variety of unprivileged users
  • Capping runtime execution at 3 seconds
  • Capping stdout to 65536 characters (resists yes/no bombs and runaway output)
  • SIGKILLing misbehaving code

License

Piston is licensed under the MIT license.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].