You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Ruby::Box support—is it possible in Ruby WASM? #645
Importantly, to enable Ruby::Box, you must specify RUBY_BOX=1 as an environment variable when starting the Ruby VM. Setting ENV[“RUBY_BOX”] = “1” from within Ruby code is too late.
For example, this works on Node.js:
importfsfrom"fs/promises";import{DefaultRubyVM}from"@ruby/wasm-wasi/dist/node";constbinary=awaitfs.readFile("./node_modules/@ruby/head-wasm-wasi/dist/ruby.wasm",);constmodule=awaitWebAssembly.compile(binary);const{ vm }=awaitDefaultRubyVM(module,{env: {RUBY_BOX: "1",},});constresult=vm.eval(` box = Ruby::Box.new box.eval <<~RUBY X = 123 RUBY puts "Ruby::Box.enabled?: #{Ruby::Box.enabled?}" puts "box::X: #{box::X}"`);
Example output:
$ node ruby-box.node.js(node:8080) ExperimentalWarning: WASI is an experimental feature and might change at any time(Use `node --trace-warnings ...` to show where the warning was created)ruby.wasm: warning: Ruby::Box is experimental, and the behavior may change in the future!See https://docs.ruby-lang.org/en/master/Ruby/Box.html for known issues, etc.Ruby::Box.enabled?: truebox::X: 123
The same applies in browsers if you instantiate the VM manually, e.g. by passing env to DefaultRubyVM:
const{ vm }=awaitDefaultRubyVM(module,{env: {RUBY_BOX: "1",},});
Note
Currently, browser.script.iife.js does not provide a way to pass environment variables from HTML.
I believe this addresses your original question and the subsequent requests.
Please let me know if there’s anything else you need. Otherwise, I think it’s fine to close this issue.
Activity
ledsun commentedon May 1, 2026
Yes,
Ruby::Boxcan run on ruby.wasm.Importantly, to enable
Ruby::Box, you must specifyRUBY_BOX=1as an environment variable when starting the Ruby VM. SettingENV[“RUBY_BOX”] = “1”from within Ruby code is too late.For example, this works on Node.js:
Example output:
The same applies in browsers if you instantiate the VM manually, e.g. by passing
envtoDefaultRubyVM:Note
Currently,
browser.script.iife.jsdoes not provide a way to pass environment variables from HTML.brandonzylstra commentedon May 2, 2026
Are there any plans to update
browser.script.iffe.jsto make it easy to pass in custom options?ledsun commentedon Aug 16, 2026
This is now supported as of ruby.wasm v2.10.0, via #649.
browser.script.iife.jsaccepts adata-envattribute containing a JSON object, soRuby::Boxcan now be enabled directly from HTML:The values in
data-envmust be strings.I believe this addresses your original question and the subsequent requests.
Please let me know if there’s anything else you need. Otherwise, I think it’s fine to close this issue.
brandonzylstra commentedon Aug 17, 2026
Thanks I'll plan to try that and report back. (I previously just altered the JS file, which has worked out well.)