Giter VIP home page Giter VIP logo

code-execution-engine's Introduction

Maintenance GitHub license npm GitHub last commit npm

Code-Execution-Engine

A fast and secure Code-Execution-Engine in Javascript.

❗This package is not secure by default. Visit Security for production projects.❗

Table of Contents

Use the package manager npm to install Code-Execution-Engine.

$ npm install code-execution-engine

Or use the yarn package manager.

$ yarn add code-execution-engine
const cee = require("code-execution-engine");

cee
  .execute("print('Hello World')", cee.languages.PYTHON3, [], "", {
    timeout: 5,
  })
  .then((result) => {
    console.log(result);
  })
  .catch((error) => {
    console.error(error);
  });

execute(input, language, [args], [stdin], [options]) → Promise<String>

Returns the result (stdout) of the executed code. If stderr is not empty, an exception will be thrown with the content of stderr.

input: string – The source code that should be executed.

language: cee.Language – Pass the language the code is written in, for example, cee.languages.PYTHON3. Supported Lanuages

args: string[] - Command-Line arguments that are passed to the script

stdin: string - Set the stdin for the script

options: IExecuteOptions

      timeout: number - Max execution time of the script. This option doesn't work on windows. Defaults to 5

Get the supported languages on your platform by calling

cee.getSupportedLanguages();
Linux / MacOS Windows
Python3 ✔️ ✔️
Python2 ✔️ ✔️
Javascript ✔️ ✔️
Ruby ✔️ ✔️
Go ✔️ ✔️
Batch ✔️
Bash ✔️
C ✔️
C++ ✔️
Java ✔️

More supported languages coming soon.

IMPORTANT: There are no security modules available for windows!

const cee = require("code-execution-engine");

const executor = new cee.LXC("[NAME OF YOUR LXC-CONTAINER]");

// Run this function after the installation of the container
executor.init({
  runners: 150,
  // limitations per runner
  maxProcesses: 64,
  maxFiles: 2048,
});

executor
  .execute("echo 'Im in a secure environment!'", cee.languages.BASH)
  .then((result) => {
    console.log(result);
  })
  .catch((error) => {
    console.error(error);
  });

To use LXC, follow the instructions below to set up LXC.

LXC's are Linux containers, that run the code in a different and secure environment. To use them, you need to install them first. LXC's are only available on Linux-Systems.

To use this package with LXC, you need to install an unprivileged container.

Follow these instructions: linuxcontainers.org

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

Inspired by: engineer-man/piston

MIT

code-execution-engine's People

Contributors

dependabot[bot] avatar poeck avatar simonkoeck avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

seiman2004

code-execution-engine's Issues

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.