MCPcopy Create free account
hub / github.com/EsperoTech/yaade / createSandboxedFunction

Function createSandboxedFunction

client/src/utils/sandboxedFunction.tsx:14–36  ·  view source on GitHub ↗
(
  args: Record<string, string>,
  script: string,
  isAsync = false,
)

Source from the content-addressed store, hash-verified

12}
13
14const createSandboxedFunction = function (
15 args: Record<string, string>,
16 script: string,
17 isAsync = false,
18) {
19 const params = Object.getOwnPropertyNames(args);
20
21 if (containsGeneratorFunction(script)) {
22 throw new Error('Generator functions are not supported');
23 }
24
25 const blacklist = [
26 ...Object.getOwnPropertyNames(window).filter(
27 (e) => e !== 'eval' && e !== 'arguments' && e !== 'btoa' && e !== 'atob',
28 ),
29 ];
30
31 params.push(...blacklist);
32 if (isAsync) {
33 script = `return (async function() {${script}})()`;
34 }
35 return new Function(...params, '"use strict";' + script);
36};
37
38const sandboxedFunction = function (args: Record<string, string>, script: string) {
39 const vals = Object.values(args);

Callers 2

sandboxedFunctionFunction · 0.85
asyncSandboxedFunctionFunction · 0.85

Calls 1

Tested by

no test coverage detected