Regenerate Sandbox regenerate-sandbox
Guide for regenerating the Hermes sandbox, the C files in API/hermes_sandbox/external that wasm2c produces from a wasm build of the VM, and for changing HermesSandboxRuntime.cpp, the JSI runtime on top of it.
Use it when the user asks to regenerate or update the sandbox, re-run wasm2c or emscripten for it, or update the sandbox C files; after a bytecode version bump, a change to the C ABI in API/hermes_abi, or a VM fix the sandbox should get; or when adding or changing JSI methods in the sandbox runtime.
- Our test
- —
- not tested yet
- GitHub stars
- 11k
- facebook/hermes
- Added by
- 0
- members
- Updated
- Dec 6
- commit 06df7c8
- Content
- 8 files
- 1 script · 24 KB
- License
- MIT
- free to use
What our test found
Not tested yet. Our model tries every skill on a realistic request and scores the result, the most popular skills first. Until then, the safety checks on the right still apply.
name: regenerate-sandbox description: > Guide for regenerating the Hermes sandbox, the C files in API/hermes_sandbox/external that wasm2c produces from a wasm build of the VM, and for changing HermesSandboxRuntime.cpp, the JSI runtime on top of it. Use when the user asks to regenerate or update the sandbox, re-run wasm2c or emscripten for it, or update the sandbox C files; after a bytecode version bump, a change to the C ABI in API/hermes_abi, or a VM fix the sandbox should get; or when adding or changing JSI methods in the sandbox runtime.
Regenerating the Hermes sandbox
The sandbox runs the Hermes VM inside wasm, translated to C, so that bugs in the VM cannot reach host memory. Its pieces:
- The module.
hermesSandboxImpl(API/hermes_sandbox/CMakeLists.txt) linkshermes_sandbox_impl.cpp, the C ABI (API/hermes_abi, mainlyhermes_vtable.cpp) and the VM into a standalone wasm module with Emscripten. wasm2c turns it intoexternal/hermes_sandbox_impl_dbg_compiled*andexternal/hermes_sandbox_impl_opt_compiled*. Thewasm-rtfiles inexternal/are the wasm2c runtime. - The host.
HermesSandboxRuntime.cppimplementsjsi::Runtimeby calling the ABI vtable that the module exports (get_hermes_abi_vtable), through a hand-written mirror,SANDBOX_CONTEXT_VTABLE_FUNCTIONS. It also implements the module's imports. - The generated C is checked in. Nothing rebuilds it, so a change to the VM, the ABI or the bytecode format reaches the sandbox only when someone regenerates it. The debug build of the host compiles the dbg files and the release build the opt files.
If this checkout has a facebook/ directory, also read .claude/skills/facebook/regenerate-sandbox-meta/SKILL.md, which covers the internal build, test and submission steps.
When to regenerate
- The bytecode version changes. The sandbox only accepts bytecode of the version it was built with.
- The C ABI changes:
hermes_abi.horhermes_vtable.cpp. - A VM fix or feature should reach the sandbox.
- Emscripten or wasm2c is upgraded.
Changes to HermesSandboxRuntime.cpp alone do not need a regeneration.
References
Read the one that matches the step you are on:
- Before changing the ABI or the mirror:
- To set up the tools and build the wasm modules and the C:
- To check the output before committing it: , which uses
- To test the result:
- When adding or changing a JSI method in
HermesSandboxRuntime.cpp: - When something fails:
Checklist
- Make the source changes: the VM, the ABI and the host runtime. The mirror changes go in the same commit as the regenerated C (see ).
- Build the host compilers and both wasm modules with the commands in
API/hermes_sandbox/README.md, with the pinned tool versions. - Check the imports and exports of both modules before running wasm2c.
- Run wasm2c for dbg and opt, then run
verify_generated.py. - Rebuild from clean build directories and check that the output is the same, byte for byte.
- Run the API tests with the debug and the release build of the host, and with UBSan.
- Update the README if the tools, flags or steps changed.
- Afterwards, update this skill with anything that went differently.