nodejs: run module in sandbox
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have this turn-based NodeJs gaming app in which developers (anyone) can submit a player-robot. My NodeJS app will load all players and let them play against each other. Because I don't know anything about the code submitted I need to run it inside a sandbox. For example, the following untrusted code might look like this: let history = []; export default class Player { constructor () { this.history = []; } move (info) { this.history.push(info); } done(result) { history.push({result: result, history: this.history}); } } Now, in my main app I