Code Monkey home page Code Monkey logo

go-sandbox's Introduction

Go Sandbox Service

A containerized service that exposes a gRPC server streaming endpoint for running an arbitrary Go code in a sandbox.

The arbitrary code runs inside multiple sandboxes using isolate.

sandbox arch

Sandbox:

  • Multiple sandboxes are created to handle concurrent requests. One sandbox serves one request at a time and keeps other requests waiting till the sandbox is available again.
  • Network calls / File creation(size) are restricted.
  • Files created inside a specific sandbox are not visible to any other sandboxes.
  • Sandboxes are cleaned up periodically.

See the full implementation in action: https://goplayground.dev

Running locally

  1. Build image

    make build
  2. Run gRPC service (server streaming)

    # starts service in localhost:8080
    make run
  3. Make RPC call to execute arbitrary code

    You get real-time output from the executing code through the streaming endpoint, mirroring local execution.

    go-sandbox-example.mov

    Request sample:

    session_id can be used to bind a sandbox to a session(execution), e.g for authenticated users. If not provided, the code will run in random sandboxes.

    {
      "code": "package main\n\nimport (\n\t\"fmt\"\n\t\"time\"\n)\n\nfunc main() {\n\tfor i := 0; i < 3; i++ {\n\t\ttime.Sleep(time.Second)\n\t\tfmt.Println(\"Hello\", i)\n\t}\n\n}\n",
      "session_id": "user_1" // optional
    }

    Response Stream:

    Success:

    {
      "output": "Hello",            // stdout/stderr from executed Go code
      "exec_err": "",               // server error
      "is_error": false,            // true for server error
      "timestamp": "1712415917223"  // stdout/err timestamp
    }

    Error:

    {
      "output": "main.go:10:8: undefined: time.Slseep",
      "exec_err": "",
      "is_error": false,
      "timestamp": "1712416529383"
    }

go-sandbox's People

Contributors

nirdosh17 avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.