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

Implementation:AIPexStudio AIPex QuickJSManager execute

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

Overview

Concrete method that executes JavaScript code inside a QuickJS WebAssembly VM with injected host APIs, resource limits, and promise resolution handling.

Description

The QuickJSManager.execute method is the core of the sandboxed execution engine. It ensures the runtime is initialized, preloads CDN modules referenced in the code, creates a new VM context via `Scope.withScopeAsync` (for automatic resource cleanup), injects global APIs (`SKILL_API`, `fs`, `console`, `fetch`, `registerTool`) via `_injectGlobalAPI`, injects the `args` variable, wraps the skill code to support the `main()` pattern, evaluates it as an ES module, and polls `executePendingJobs` until the promise resolves or a 60-second timeout is reached. Uses the RELEASE_SYNC variant (required for Chrome extension CSP restrictions).

Usage

Called internally by `SkillExecutor.executeScript`. Not called directly by consumers, but documented as the implementation of sandboxed code execution.

Code Reference

Source Location

  • Repository: AIPex
  • File: packages/browser-runtime/src/lib/vm/quickjs-manager.ts
  • Lines: L41-707 (class), L375-470 (execute), L310-360 (preloadModules), L562-707 (_injectGlobalAPI, bindObject)

Signature

async execute(
  code: string,
  context: ExecutionContext,
  apiBridge: SkillAPIBridge
): Promise<any>

interface ExecutionContext {
  skillId: string;
  workingDir: string;
  args?: any;
}

// Internal: async preloadModules(code: string): Promise<void>
// Internal: _injectGlobalAPI(vm, apiBridge, scope): void
// Internal: bindObject(vm, obj, name?): void

// Singleton: export const quickjs = new QuickJSManager();

Import

import { quickjs } from "@aipexstudio/browser-runtime";
// execute is called internally by SkillExecutor

I/O Contract

Inputs

Name Type Required Description
code string Yes Skill JavaScript code (must define main() or module.exports)
context.skillId string Yes Skill identifier
context.workingDir string Yes Working directory in ZenFS
context.args any No Arguments passed to main()
apiBridge SkillAPIBridge Yes Host API bridge (fs, console, fetch, registerTool)

Outputs

Name Type Description
returns any Return value from main() or module.exports

Usage Examples

Internal Execution Flow

// Called internally by SkillExecutor.executeInVM:
const result = await quickjs.execute(
  scriptContent,   // skill JS code
  {
    skillId: "my-skill",
    workingDir: "/skill_my-skill",
    args: { input: "data" },
  },
  apiBridge  // createSkillAPIBridge({ skillId, onToolRegister })
);
// result = return value from skill's main(args)

Skill Code Pattern (Inside VM)

// Skill script runs inside QuickJS with injected globals:
async function main(args) {
  console.log("Starting skill with args:", args);
  const data = await fs.readFile("config.json", "utf8");
  await fs.writeFile("output.txt", "processed");
  return { success: true };
}

// registerTool is also available:
await registerTool({
  name: "my_tool",
  description: "Does something useful",
  parameters: { type: "object", properties: {} },
});

Related Pages

Implements Principle

Uses Heuristics

Requires Environment

Page Connections

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