Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Heuristic:AIPexStudio AIPex VM Resource Limits

From Leeroopedia
Knowledge Sources
Domains Sandboxing, Security, Optimization
Last Updated 2026-10-24 12:00 GMT

Overview

QuickJS VM sandboxes skills with a 100MB memory limit, 1MB stack, and synchronous-only WASM variant to prevent resource exhaustion and comply with Chrome extension CSP.

Description

The QuickJS Manager creates a WASM-based JavaScript sandbox for executing untrusted user-supplied skill code inside the Chrome extension. The runtime is configured with hard resource limits: 100MB of memory (`setMemoryLimit(100 * 1024 * 1024)`) and a 1MB stack (`setMaxStackSize(1024 * 1024)`). Additionally, the `RELEASE_SYNC` variant of QuickJS is used instead of the ASYNC variant because Chrome extension CSP forbids `wasm-eval`, which the asyncify (ASYNC) variants require. The module loader is synchronous, so all ESM dependencies must be preloaded into the module cache before skill execution begins.

Usage

Use this heuristic when debugging skill execution failures related to memory, stack overflows, or module loading. If a skill exceeds 100MB of memory, the VM will terminate with an OOM error. If a skill attempts to import a module that was not preloaded, the loader throws "Module not found." If you need async execution, you cannot use the ASYNC variant in a Chrome extension — you must structure skill code to work synchronously.

The Insight (Rule of Thumb)

  • Action: Set `runtime.setMemoryLimit(100 * 1024 * 1024)` and `runtime.setMaxStackSize(1024 * 1024)` on QuickJS runtime initialization.
  • Value: Memory: 100MB. Stack: 1MB. Variant: `RELEASE_SYNC` (not asyncify).
  • Trade-off: 100MB is sufficient for most skill scripts but may be insufficient for data-heavy processing. The sync-only constraint means no `await` inside QuickJS module loading — all dependencies must be preloaded.
  • Compatibility: `RELEASE_SYNC` is required for Chrome extensions due to CSP. The ASYNC variant would work in non-extension contexts (e.g., Node.js).

Reasoning

Skills are untrusted user-supplied code packages (ZIP files) that execute inside the extension's service worker. Without memory limits, a malicious or buggy skill could consume all available memory, crashing the extension. The 100MB limit is generous enough for typical automation scripts while preventing runaway allocations. The 1MB stack prevents deep recursion attacks. The synchronous module loader is a consequence of the `RELEASE_SYNC` variant — it cannot perform async `fetch()` calls during module resolution, so all dependencies (including transitive dependencies fetched from esm.sh) must be preloaded into the `moduleCache` Map before execution begins.

Code Evidence

Memory and stack limits from `packages/browser-runtime/src/lib/vm/quickjs-manager.ts:113-115`:

// Set memory and stack limits
this.runtime.setMemoryLimit(100 * 1024 * 1024); // 100MB
this.runtime.setMaxStackSize(1024 * 1024); // 1MB

RELEASE_SYNC variant requirement from `packages/browser-runtime/src/lib/vm/quickjs-manager.ts:1-8`:

/**
 * Note: Using RELEASE_SYNC variant instead of ASYNC to avoid CSP issues in Chrome extensions.
 * Chrome extensions don't allow 'wasm-eval' which is required by asyncify variants.
 */
import { default as RELEASE_SYNC } from "@jitl/quickjs-ng-wasmfile-release-sync";

Synchronous module loader throwing on cache miss from `packages/browser-runtime/src/lib/vm/quickjs-manager.ts:120-152`:

this.runtime.setModuleLoader((moduleName: string) => {
  // 1. Built-in modules (fs, etc.)
  if (moduleName === "fs") {
    return `export default ${JSON.stringify(fs)}`;
  }
  // 2. Check cache for preloaded modules
  const cachedModule = this.moduleCache.get(moduleName);
  if (cachedModule) {
    return cachedModule;
  }
  // 4. Module not found
  return `throw new Error('Module not found: ${moduleName}. Module must be preloaded before execution.');`;
});

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment