Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions server/utils/sandbox.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
const Safeify = require('safeify').default;

module.exports = async function sandboxFn(context, script) {
let result
// 创建 safeify 实例
const safeVm = new Safeify({
timeout: 3000,
asyncTimeout: 60000
})

script += "; return this;";
// 执行动态代码
const result = await safeVm.run(script, context)

try {
// 执行动态代码
result = await safeVm.run(script, context)
} catch (error) {
console.log('error: ', error)
}

// 释放资源
safeVm.destroy()
Expand Down