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

Showing Posts 1 to 2

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

wojtekmach
Hey everyone! Req is an HTTP client for Elixir that I’ve been working on for quite some time. There is already a lot of HTTP clients out...
New
handnot2
Samly can be used to enable SAML 2.0 Single Sign On in a Plug/Phoenix application. This library uses Erlang esaml to provide plug enabl...
New
woylie
Flop is an Elixir library that applies filtering, ordering and pagination parameters to your Ecto queries. offset-based pagination with...
New
MRdotB
I needed to reuse React components from my Chrome extension in my Phoenix/LiveView backend. I noticed that for Svelte/Vue, there are live...
New
garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
New
marciok
Hi there! We created Gust: A task orchestrator inspired by Airflow. For those who have never heard about Aiflow, it’s a Python-based wor...
New
fuelen
Hi all! I want to present a small library which provides a mix task for generating an Entity-Relationship Diagram for Ecto schemas. You...
New

Other Trending Topics Top

mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
AstonJ
This showed up on my feed.. anyone heard of it? Just hype? Ox Alpha is a reasoning model designed for coding, sustained ag...
New
sergio
It’s not that it’s vocabulary is too advanced. It’s something worse. I get lost trying to follow even a paragraph written by Claude. It’...
New
sorenone
Today we’re releasing Oban for Python. Not an Oban client in Python. Not a pythonx wrapper embedded in Elixir. Nope, it’s a fully operati...
New
akoutmos
@hugobarauna, Dr. Dimitrios Koutmos (my brother) and I (Alex Koutmos) have been hard at work on writing a book on how you can use Elixir ...
New
pferriby
Introductory paragraph I’ll be looking for a keen junior or someone that has a couple of years experience in the real world (so you’ve be...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews