DocsErrors

Sandbox Restrictions

QSL strategies run in a secure sandbox. Certain JavaScript APIs are blocked to ensure strategies are deterministic, safe, and cannot access external resources.

Forbidden Global APIs

The following identifiers are blocked at the AST level — using them anywhere in your code triggers an immediate error:

Blocked APIReason
eval, FunctionCode injection risk
require, importModule loading blocked
fetch, XMLHttpRequestNetwork access blocked
setTimeout, setInterval, setImmediateAsync execution blocked
clearTimeout, clearIntervalTimer manipulation blocked
process, global, globalThisSystem access blocked
Proxy, ReflectMetaprogramming blocked
WebSocketNetwork access blocked
localStorage, sessionStorageBrowser storage blocked
document, window, navigatorDOM access blocked
__dirname, __filenameFile system info blocked
BufferBinary data blocked
SharedArrayBufferShared memory blocked

Non-Deterministic Code

Strategies must produce identical results on every run with the same inputs. These patterns are blocked:

// Blocked — random values Math.random(); // Blocked — current time dependency new Date(); Date.now(); // Blocked — non-deterministic iteration order for (let key in obj) { }

Control Flow Restrictions

// Blocked — potential infinite loops while (condition) { } do { } while (condition); // Blocked — recursion (function calling itself) function calculate(n) { return calculate(n - 1); // recursion not allowed } // Allowed — for loops are permitted for (let j = 0; j < 10; j++) { }

What You CAN Use

AvailableExamples
Math (except Math.random)Math.abs(), Math.max(), Math.min(), Math.floor(), Math.log(), Math.sqrt()
Arrays[].push(), [].map(), [].filter(), [].reduce(), [].slice()
Objects{}, Object.keys(), Object.values()
Primitive operationsArithmetic, comparisons, string operations
for loopsfor (let i = 0; ...), for (const x of arr)
ctx and qFull strategy API and helper functions

If You See a Sandbox Error

  1. Check the error message — it names the forbidden API
  2. Remove or replace the blocked call
  3. Use ctx.state to store values between bars instead of closures or globals
  4. Use q helper functions instead of implementing custom math
sandboxforbiddensecurityrestrictedevalrequirefetchsetTimeoutimport