Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/Houfeng/safeify
📦 Safe sandbox that can be used to execute untrusted code.
https://github.com/Houfeng/safeify
sandbox
Last synced: 3 months ago
JSON representation
📦 Safe sandbox that can be used to execute untrusted code.
- Host: GitHub
- URL: https://github.com/Houfeng/safeify
- Owner: Houfeng
- License: apache-2.0
- Created: 2018-04-18T03:15:01.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2023-01-23T21:55:52.000Z (about 2 years ago)
- Last Synced: 2024-08-02T06:24:30.594Z (7 months ago)
- Topics: sandbox
- Language: TypeScript
- Homepage:
- Size: 2.84 MB
- Stars: 487
- Watchers: 13
- Forks: 30
- Open Issues: 32
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-nodejs - safeify - Safe sandbox that can be used to execute untrusted code. ![](https://img.shields.io/github/stars/Houfeng/safeify.svg?style=social&label=Star) (Repository / Sandbox)
README
# Safeify
[![npm](https://img.shields.io/npm/l/safeify.svg)](LICENSE.md)
[![NPM Version](https://img.shields.io/npm/v/safeify.svg)](https://www.npmjs.com/package/safeify)
[![Build Status](https://www.travis-ci.org/Houfeng/safeify.svg?branch=master)](https://www.travis-ci.org/Houfeng/safeify)
[![Coverage Status](https://coveralls.io/repos/github/Houfeng/safeify/badge.svg?branch=master)](https://coveralls.io/github/Houfeng/safeify?branch=master)
[![npm](https://img.shields.io/npm/dt/safeify.svg)](https://www.npmjs.com/package/safeify)# 说明
Safeify 可让 Node 应用安全的隔离执行非信任的用户自定义代码,[了解详细](//github.com/Houfeng/safeify/blob/master/DOC.md)
# 安装
```sh
npm install safeify -S
```# 使用
```ts
import { Safeify } from "safeify";(async ()=>{
// 创建 safeify 实例
const safeVm = new Safeify({
timeout: 3000,
asyncTimeout: 60000
});// 定义 context
const context = {
a: 1,
b: 2,
system: {
add(a: number, b: number) {
return (a + b) * 2;
}
}
};// 执行动态代码
const result= await safeVm.run(`return system.add(1,2)`, context);
console.log('result', result);// 释放资源
safeVm.destroy();
})();
```