Jskalc

Jskalc

I’ve just released MquickjsEx, an Elixir library for embedding JavaScript execution directly in your BEAM process using MQuickJS. It’s a new project that got a huge attention on hackernews.

Why?

I built this to let LLMs execute JavaScript code securely with minimal overhead. When an LLM generates JS code for data transformation or custom logic, I wanted to run it in a sandbox where I control exactly what functions are available - no filesystem, no network, just the tools I expose.

I will be also experimenting if it would be possible to create a very fast Server Side Renderer for my other library, LiveVue.

What is it?

MquickjsEx wraps MQuickJS (Fabrice Bellard’s minimal JS engine) via NIFs. Similar to what pythonx does for Python, but the API is inspired by tv-labs/lua.

Key points:

  • No external runtime - no Node.js, Bun, or Deno installation
  • In-process - runs inside the BEAM via NIFs, no subprocess spawning
  • Tiny footprint - MQuickJS can run in as little as 10KB RAM (default 64KB)
  • Sandboxed - no filesystem or network access by default
  • Bidirectional - call JS from Elixir and Elixir from JS

Usage

# Create context and evaluate code
{:ok, ctx} = MquickjsEx.new()
{:ok, 3} = MquickjsEx.eval(ctx, "1 + 2")

# Expose Elixir functions to JavaScript
ctx = MquickjsEx.set!(ctx, :fetch_data, fn [table] -> MyApp.Repo.all(table) end)
{result, _ctx} = MquickjsEx.eval!(ctx, "fetch_data('users').length")

# Define reusable API modules
defmodule MathAPI do
  use MquickjsEx.API, scope: "math"
  defjs add(a, b), do: a + b
end

{:ok, ctx} = MquickjsEx.new()
{:ok, ctx} = MquickjsEx.load_api(ctx, MathAPI)
{:ok, 5} = MquickjsEx.eval(ctx, "math.add(2, 3)")

Important Limitations

MQuickJS implements a subset of JavaScript close to ES5 with a stricter mode. You need to know these:

Arrays cannot have holes:

a = []
a[10] = 1;  // TypeError - can only extend at end
[1, , 3]    // SyntaxError

No direct eval:

eval('1 + 2');       // Forbidden
(1, eval)('1 + 2');  // OK (indirect eval)

No value boxing:

new Number(1)  // Not supported

Limited Date support:
Only Date.now() works.

ASCII-only for some string ops:
toLowerCase() / toUpperCase() only handle ASCII.

Re-execution pattern for callbacks:
When JS calls an Elixir function, execution pauses, Elixir runs the callback, then JS re-executes from the start with cached results. This means your JS code should be idempotent - no side effects that accumulate on replay.

Installation

def deps do
  [{:mquickjs_ex, "~> 0.1.0"}]
end

Full docs and more examples: GitHub - Valian/mquickjs_ex: Embedded JS runtime for Elixir based on MQuickJS · GitHub.

I need to disclose, it was created by collaborating closely with Claude Code Opus 4.5, otherwise it would be not possible.

Feedback welcome - this is the first release. Hope you’ll like it!

https://github.com/Valian/mquickjs_ex

First 2 of 2 Posts Switch mode

garrison

garrison

Do you foresee the limited syntax (i.e. no es6) posing a problem for SSR with LiveVue? The no holes thing is kinda odd as I would think it wouldn’t be too hard to grow the array accordingly, but I’m sure Bellard is wiser than I.

As an aside, it’s interesting that nearly every new library posted here lately has been written with Claude. It would appear the vibes are hitting critical mass.

Jskalc

Jskalc OP

Do you foresee the limited syntax (i.e. no es6) posing a problem for SSR with LiveVue?

I’m not sure. Will investigate further soon to understand both feature and performance limitations.

That project exists because on Sunday I noticed an interesting library and though “huh, it would be nice to have it in Elixir. Maybe Opus could handle it?”.

And indeed, it handled it fairly well!

— All posts loaded —

Where Next? Top

Trending in Announcing Top

bluzky
You may know https://ui.shadcn.com/, a UI component library for React. I really love it’s design style and components. I’ve built some co...
387 15136 120
New
woylie
Flop is an Elixir library that applies filtering, ordering and pagination parameters to your Ecto queries. offset-based pagination with...
New
JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
shahryarjb
The Chelekom project is a library of Phoenix and LiveView components generated via Mix tasks to fit developer needs seamlessly. One of i...
New
woylie
Phoenix components for pagination, sortable tables and filter forms with Flop and (optionally) Ecto. pagination cursor pagination sorta...
New
kip
Please say hi to a new lib, Astro that aims to deliver easy-to-consume astronomy calculations of practical use. For now it only calculat...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New

Other Trending Topics Top

juhalehtonen
There has been a thread to discuss the Stack Overflow Developer Survey on this forum every year since 2018, so here’s yet another one for...
New
type1fool
I just stumbled on a newly redesigned elixir-lang.org. :tada: It looks like @Software_Mansion did the work, and I think it is generally a...
New
akoutmos
@hugobarauna and I (Alex Koutmos) have been hard at work on writing a book on Nerves that takes you from simply blinking LEDs to building...
New
spammy
I’m looking to build a personal workflow to quickly deploy web applications written in elixir/phoenix, for local consumption (ie not on t...
New
alexslade
Fly’s CEO posted this recently - Turn And Face The Strange · The Fly Blog It says that Fly is going all-in on sprites, which is a worry ...
New
bartblast
Hey folks, I just published a post about Hologram’s funding and where the project goes next - the short version: Curiosum as Main Spons...
New

We're in Beta

About us Mission Statement