GithubHelp home page GithubHelp logo

docker-pypy-sandbox's Introduction

Build Status

Docker PyPy Sandbox

This is a fork of docker-python-sandbox, intended to be used with PyPy instead of the typical Python compiler (CPython). Unless you know that you need PyPy, it is advised that you stick with the original package as there is some degraded functionality in this fork. That said, most of the integration tests from docker-python-sandbox pass for this repository as well.

Why PyPy over CPython?

PyPy provides a robust sandboxing feature, whereas CPython is notoriously difficult to lock down. PyPy in combination with Docker is a good place to start when exploring arbitrary Python code execution.

Example use (Linux)

  1. Install Docker
  2. mkdir docker-pypy-sandbox-example && cd docker-pypy-sandbox-example
  3. npm init (press return until done)
  4. Install the library: npm install --save docker-pypy-sandbox
  5. Pull the docker image used by the library: docker pull murtyjones/docker-pypy-sandbox
  6. Create a new file, index.js, with the following code:
let Sandbox = require('docker-pypy-sandbox')

const poolSize = 5
let mySandbox = new Sandbox({poolSize})

mySandbox.initialize(err => {
  if (err) throw new Error(`unable to initialize the sandbox: ${err}`)
  
  const code = 'print "Hello, world!"'
  const timeoutMs = 2 * 1000
  
  mySandbox.run({code, timeoutMs}, (err, result) => {
    if (err) throw new Error(`unable to run the code in the sandbox: ${err}`)
    
    console.log(result.stdout); // Hello, world!
  })
});
  1. node index.js

Example use (macOS)

NOTE: For an unidentified reason, this library does not work well on macOS. The instructions below will help you to use the library for testing purposes, but this library should only be used in production on a Linux server.

  1. Install Docker
  2. mkdir docker-pypy-sandbox-example && cd docker-pypy-sandbox-example
  3. npm init (press return until done)
  4. Install the library: npm install --save docker-pypy-sandbox
  5. Pull the docker image used by the library: docker pull murtyjones/docker-pypy-sandbox
  6. Create a new file, index.js, with the following code:
let Sandbox = require('docker-pypy-sandbox')

const poolSize = 5
let mySandbox = new Sandbox({poolSize})

mySandbox.initialize(err => {
  if (err) throw new Error(`unable to initialize the sandbox: ${err}`)
  
  const code = 'print "Hello, world!"'
  const timeoutMs = 2 * 1000
  
  mySandbox.run({code, timeoutMs}, (err, result) => {
    if (err) throw new Error(`unable to run the code in the sandbox: ${err}`)
    
    console.log(result.stdout); // Hello, world!
  })
});
  1. docker run -it --rm -p 3000:3000 murtyjones/docker-pypy-sandbox
  2. open a new tabL CMD + T
  3. node index.js --mac=true

docker-pypy-sandbox's People

Contributors

christophetd avatar marcbachmann avatar murtyjones avatar

Stargazers

 avatar  avatar

Watchers

 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.