https://github.com/mdp/pitboss
Run dubious code in node!
https://github.com/mdp/pitboss
Last synced: about 1 year ago
JSON representation
Run dubious code in node!
- Host: GitHub
- URL: https://github.com/mdp/pitboss
- Owner: mdp
- Created: 2012-09-23T17:10:46.000Z (over 13 years ago)
- Default Branch: master
- Last Pushed: 2019-05-06T16:59:39.000Z (about 7 years ago)
- Last Synced: 2025-03-28T18:08:58.719Z (about 1 year ago)
- Language: CoffeeScript
- Size: 12.7 KB
- Stars: 6
- Watchers: 3
- Forks: 4
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Deprication and better alternative
This library is old, unmaintained and not very useful. Please see [vm2](https://github.com/patriksimek/vm2#readme) if you're need something similar.
[](http://travis-ci.org/mdp/pitboss)

# Pitboss
## A module for running untrusted code
### Runs JS code and returns the last eval'd statement
code = """
num = num % 5;
num;
"""
pitboss = new Pitboss(code)
pitboss.run {num: 23}, (err, result) ->
assert.equal 3, result
### Handles processes that take too damn long
code = """
while(true) { num % 3 };
"""
pitboss = new Pitboss code
timeout: 2000
pitboss.run {num: 23}, (err, result) ->
assert.equal "Timeout", err
### Doesn't choke under pressure(or shitty code)
code = """
What the fuck am I writing?
"""
pitboss = new Pitboss code
timeout: 2000
pitboss.run {num: 23}, (err, result) ->
assert.equal "VM Syntax Error: SyntaxError: Unexpected identifier", err
### Doesn't handle this! But 'ulimit' does!
code = """
str = ''
while(true) { str = str + "Memory is a finite resource!" };
"""
pitboss = new Pitboss code
timeout: 10000
pitboss.run {num: 23}, (err, result) ->
assert.equal "Process failed", err
And since Pitboss forks each process, ulimit kills only the runner