Experimental code execution microservice based on Docker containers.

ranna

ランナー - Experimental code runner microservice based on Docker containers.

PLEASE READ BEFORE USE

First of all, this project is currently work in progress and not fully finished.
Also, this service allows arbitrary code execution in Docker containers. This will be a high security risk! If you want to use this service, only use this on a separate, encapsulated server environment!

📃 Todo

👉 Take a look in the issue tracker.

🛠 Architecture

Maybe, to make my thoughts behind the project more clear, here is a little introduction into the project's architecture.

As you can see, the project is split up in different services.

  • REST API: The REST API service is the main entrypoint for code execution.
  • Config Provider: All services need specific configuration. These are obtained by this service.
  • Spec Provider: ranna works with specs, which describe the runner environments for the Sandbox Provider. It provides a map of language specifiers (like go, or python3) with their specific runner specs.
  • Sandbox Manager: A higher levbel abstraction to execute code in sandboxes. Also keeps track of running containers to clean them up after teardown.
  • Sandbox Provider: This is the high level API to create a sandbox environment where the passed code can be run inside and the output can be obtained from.
  • Namespace Provider: This service is responsible for generating unique namespace identifiers which can be used to pass the provided code as file into the sandbox.
  • File Provider: This service is responsible for creating the nessecary directory structure and the file, containing the code, which is then passed to the sandbox to be executed.

🚀 Setup

👉 Take a look in the wiki.

📡 REST API

👉 Take a look in the wiki.

📦 Client Package

ranna also provides a Go client package available in pkg/client.

See the simple example implementation how to use the client package.

Here you can find some handy documentation for the provided packages.


© 2021 Ringo Hoffmann (zekro Development).
Covered by the MIT License.

Owner
ranna
Run some code on the web. 👟👩‍💻🌐
ranna
Comments
  • proposal: code environment templates

    proposal: code environment templates

    Hey ^^.

    I recently got the idea to implement so-called code environment templates into ranna to allow code execution without having to provide the whole boilerplate (package, imports, main function) that surrounds the expression to evaluate. I also made up my mind on how this could possibly be implemented in the current solution to create as little friction as possible.

    Specification implementation

    First of all, spec.yml entries receive an additional field called template:

    golang:
      image: 'golang:alpine'
      entrypoint: 'go run'
      filename: 'main.go'
      example: |-
        package main
        import "fmt"
        func main() {
        	fmt.Println("Hello world!")
        }
      template: |-
        package main
        import "fmt"
        func main() {
        	$${CODE}
        }
    

    $${CODE} gets replaced with the user-provided expression before passing the whole construct down to the execution runtime.

    API implementation

    The POST /v1/exec request body receives an additional field called inline_expression (boolean). If this field is set to true, the contents of the code field get inserted in the desired template. If the specification of the targetted language does not support inline templating (the template field is omitted), an error is returned. The inline_expression field is set to false by default to not break existing API clients.

    {
      "language": "go",
      "code": "fmt.Println(\"Cool! Inline expressions!\")",
      "inline_expression": true,
      "arguments": [],
      "environment": {}
    }
    

    Please let me know what you think of this idea and my suggested example on how to implement it! If you would like to implement this into ranna, I'd love to help with a PR.

  • Sort languages alphabetically

    Sort languages alphabetically

    I have sorted the spec file and formatted it uniformly. The languages "names" are now sorted alphabetically and everything is formatted the same. I do this in an extra PR to avoid merge conflicts with the other two PRs.

  • inline: allow multiple import statements

    inline: allow multiple import statements

    This allows stuff like

    // The 'fmt' package allows us to print something to our console:
    import "fmt"
    fmt.Println(123)
    
    // We can also pass in other nested expressions:
    import "strings"
    fmt.Println(strings.ToLower("HELLO, WORLD!"))
    
  • Adding racket as language

    Adding racket as language

    In this PR I have added the Racket programming language. Because I'm working with the school with it right now, ranna offers itself for a short test and share. Since it is probably in the interest of the project, I would also like to add this programming language to the project.

    The commands I could execute with Docker I have tested all but I'm not sure if it all works in ranna Working Dir. Therefore please test once.

  • Code Highlighting doesn't work with Golang

    Code Highlighting doesn't work with Golang

    If you try to execute this script in Ranna and select golang as the Language, it doesn't highlight any word.

    package main
    
    import "fmt"
    
    func main() {
        fmt.Println("Hello World.")
    }
    

    O17XUNtfW7

  • Proposal: WebSocket API

    Proposal: WebSocket API

    Alongside the REST API, the ranna engine should also be accessible via a WebSocket API which gives real-time log output and runtime information.

    The communication is based on operations and events encoded in JSON objects.

    Operations

    Operations are specified as enumerable operation codes and can get passed arguments in form of a key-value pair map. You can also optionally pass a nonce value which will be also set on corresponding events related to the operation.

    Example

    {
      "op": 1,
      "nonce": 23216,
      "args": {
        "language": "go",
        "code": "package main; import \"fmt\"; func main() {fmt.Println(\"Hello world!\")}"
      }
    }
    

    Operation Codes

    | Code | Name | Description | |-------|--------|--------------| | 0 | PING | Pings the WebSocket API. | | 1 | EXEC | Invoke a code execution. | | 2 | KILL | Kill a running operation. |

    Events

    Events carry enumerable event codes which specify the type of event as well as a payload with the events data. Also, when the event was invoked corresponding to a previous operation which has been passed a nonce, the event will also carry the passed nonce.

    Example

    {
      "code": 2,
      "nonce": 23216,
      "data": {
        "runid": "as98234sa",
        "stdout": "Hello world!"
      }
    }
    

    Event Codes

    | Code | Name | Description | |-------|--------|--------------| | 0 | PONG | Response event to the PING operation. | | 1 | ERROR | An error event. | | 2 | SPAWN | Indicates a spawned execution instance. It also carries a unique ID of the execution created. | | 3 | LOG | Indicates a log output from a running execution. It carries the unique execution ID as well as the STDERR or STDOUT value. | | 4 | STOP | Indicates the controlled finish of a execution run. | | 5 | KILL | Indicates that the run has been killed. |

  • Update openjdk to LTS 17

    Update openjdk to LTS 17

    With the release of the new Java LTS version I also want to add the new version to this project. For this I added Java 17 to the specs and linked the "java" spec to the new version.

  • bash/ash/sh env often returns empty output

    bash/ash/sh env often returns empty output

    When executing short commands using the ash spec, the result will mostly be empty. image

    This is probably a timing issue, because this is working completely fine. image

  • Add alias to spec

    Add alias to spec

    Add aliases to spec in form of spec pointers. This would look like following in the spec configuration:

    openjdk-11:
      image:      'openjdk:11'
      entrypoint: 'java'
      filename:   'Main.java'
    
    java:
      use:        'openjdk-11'
    
  • [PHP] Check if code is inline

    [PHP] Check if code is inline

    My proposal is to check if the given php code is inline or not and then handle it accordingly. Either by ignoring it/throwing an error or adding the necessary parts.

Podman: A tool for managing OCI containers and pods

Podman: A tool for managing OCI containers and pods Podman (the POD MANager) is a tool for managing containers and images, volumes mounted into those

Jan 1, 2023
a tool for getting metrics in containers

read metrics in container if environment is container, the cpu ,memory is relative to container, else the metrics is relative to host. juejing link :

Oct 13, 2022
Apptainer: Application containers for Linux

Apptainer NOTE: The apptainer repo is currently working towards a v1.0.0 release and not ready for production in its current state. Until then, use th

Jan 6, 2023
Lithia is an experimental functional programming language with an implicit but strong and dynamic type system.

Lithia is an experimental functional programming language with an implicit but strong and dynamic type system. Lithia is designed around a few core concepts in mind all language features contribute to.

Dec 24, 2022
Experimental Monika After Story persistent data loader written in Go

Go Persistent Loader This project is an experiment on loading/deserializing Monika After Story persistent (save) file into memory. Currently it contai

May 10, 2022
An experimental distribution of Temporal that runs as a single process

Temporalite ⚠️ This project is experimental and not suitable for production use. ⚠️ Temporalite is a distribution of Temporal that runs as a single pr

Dec 31, 2022
An experimental vulkan 3d engine for linux (raspberry 4)

protomatter an experimental vulkan 3d engine for linux (raspberry 4).

Nov 14, 2021
An experimental programming language.

crank-lang An experimental & interpreted programming language written in Go. Features C like syntax Written in Golang Interpreted Statically Typed Dis

Dec 6, 2021
Example project for Temporal microservice orchestarion.
Example project for Temporal microservice orchestarion.

Temporal Microservice Introduction This project is created to understand Temporal's Microservice approachment. The repo contains: Example Temporal Mic

Oct 4, 2022
A project that provides an in-memory key-value store as a REST API. Also, it's containerized and can be used as a microservice.

Easy to Use In-Memory Key-Value Store A project that provides an in-memory key-value store as a REST API. Also, it's containerized and can be used as

Mar 6, 2022
The High Code Framework (low-code for devs)

hof - the high code framework The hof tool tries to remove redundent development activities by using high level designs, code generation, and diff3 wh

Dec 24, 2022
🎄 My code for the Advent of Code of year 2021 in Go.

Advent of Code 2021 This repository contains all code that I wrote for the Advent of Code 2021. This year I chose to try and learn Go. Enjoy! Built wi

Dec 9, 2021
This Go based project of Aadhyarupam Innovators demonstrate the code examples for building microservices, integration with cloud services (Google Cloud Firestore), application configuration management (Viper) etc.

This Go based project of Aadhyarupam Innovators demonstrate the code examples for building microservices, integration with cloud services (Google Cloud Firestore), application configuration management (Viper) etc.

Dec 22, 2022
Docker CE

Docker CE ⚠️ This repository is now deprecated and will be archived ⚠️ Starting with the Docker 20.10 release, packages for the Docker Engine and Dock

Jan 6, 2023
TUI Client for Docker
TUI Client for Docker

docui - TUI Client for Docker Written in Go About docui docui is a TUI Client for Docker. It can do the following: image search/pull/remove save/impor

Dec 28, 2022
Generate random, pronounceable, sometimes even memorable, "superhero like" codenames - just like Docker does with container names.

Codename an RFC1178 implementation to generate pronounceable, sometimes even memorable, "superheroe like" codenames, consisting of a random combinatio

Dec 11, 2022
Workaround for running ubuntu:21.10, fedora:35, and other glibc >= 2.34 distros on Docker <= 20.10.9

clone3-workaround: Workaround for running ubuntu:21.10, fedora:35, and other glibc >= 2.34 distros on Docker <= 20.10.9 Old container engines such as

Dec 1, 2022
Monitoring Go application inside docker container by InfluxDB, Telegraf, Grafana
Monitoring Go application inside docker container by InfluxDB, Telegraf, Grafana

REST API for TreatField app Docker compose for TIG and Golang simple app: https://github.com/tochytskyi/treatfield-api/blob/main/docker-compose.yml Gr

Nov 6, 2021
A Simple Bank Web Service implemented in Go, HTTP & GRPC, PostgreSQL, Docker, Kubernetes, GitHub Actions CI

simple-bank Based on this Backend Master Class by TECH SCHOOL: https://youtube.com/playlist?list=PLy_6D98if3ULEtXtNSY_2qN21VCKgoQAE Requirements Insta

Dec 9, 2021