Run code in mini-program sandbox
mp_sandbox_runRuns arbitrary JavaScript in an offline WeChat Mini Program sandbox to load app-service bundles, call SDK signing functions, analyze encryption logic, and extract runtime data.
Instructions
在离线沙箱中加载小程序 bundle (app-service.js),执行任意 JS 代码。用于调用 SDK 签名函数、分析加密逻辑、提取运行时数据。需要先 mp_analyze 解包。 【eval 作用域契约】代码运行在 ESM AsyncFunction 里,注入 5 个参数: · ctx —— 沙箱上下文 (ctx.sandbox / ctx.requireMod / ctx.wpRequire / ctx.setTimestamp 等) · requireMod(path) —— 按 WeChat 模块路径取模块;wpRequire(id) —— 按 webpack 数字 id 取模块(惰性、不引导 app) · sandbox —— 沙箱全局对象:微信全局走 sandbox.wx / sandbox.getApp(),模块工厂里 self===sandbox · runInContext(code, ms=8000) —— 在沙箱 realm 内【带超时】执行(同步死循环会抛 timeout 而非拖死);JSVMP/VMP 签名调用建议用它 注意:这是 ESM 上下文,没有 node 的 require;要用 globalThis.crypto / Buffer。 分包里的签名 SDK(依赖主包 runtime)用 bundle_paths 传[主包,分包]协同加载。
Tool call template
Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {
"appid": "<appid>",
"code": "<code>"
},
"name": "mp_sandbox_run"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| ua | No | 覆盖 navigator.userAgent (VMP 常把 UA 编进签名,需与目标客户端一致) | |
| code | Yes | 要执行的 JS 代码;可用 ctx/requireMod/wpRequire/sandbox/runInContext | |
| appid | Yes | 小程序 appid | |
| device | No | 真机种子 JSON:覆盖 wx 系统/设备信息字段(如 {"platform":"android","system":"Android 14","model":"...","screenWidth":414,"screenHeight":896,"SDKVersion":"3.16.1"}),使离线签名环境指纹与目标设备一致。不传则用默认。 | |
| storage | No | 预设 wx storage JSON (如 '{"key":"value"}') | |
| timeout_ms | No | 沙箱进程整体超时 (默认 60000) | |
| bundle_path | No | 自定义 app-service.js 路径 (默认按 appid 自动查找) | |
| bundle_paths | No | 多 bundle 协同加载[主包,分包,...],顺序拼接单次载入(分包签名 SDK 依赖主包 runtime 时用) |