Embedding EYG into Gleam opens safe scripting for BEAM and JS apps

What’s happening
EYG is a small, type-safe scripting language with managed side effects, and a new guide walks developers through embedding it inside Gleam programs. Gleam itself is unusual: it targets two great runtimes — JavaScript and the BEAM (Erlang) VM — so embedding a sandboxed language here isn’t just neat, it’s flexible. Want a plugin system that doesn’t open Pandora’s box? This is the kind of thing that makes you sit up and take notice.
Why embed
Think Lua, but safer. An embedded script language gives users a programmable interface for configuration, plugins, or mods without letting them rewrite your source or roam your file system. The guide points out exactly that advantage: because EYG effects must be explicitly implemented by the host, scripts can’t perform IO or other sensitive operations unless you give them permission. That’s not just convenience; it’s containment — the current trend toward sandboxed extensibility echoing WebAssembly’s popularity.
How it works
The guide shows a minimal setup: add the eyg_analysis, eyg_interpreter, eyg_parser and touch_grass packages to your Gleam project, parse EYG source, hand it to the interpreter, and loop on the runner’s return value. For simple pure config — think name and timeout values — the interpreter returns Ok(value). If you author EYG programs via a structural editor instead of text, you can skip the parser and use the tree module to decode the IR JSON. Short, tidy, and explicit.
Handling side effects (the emotional beat)
Here’s the moment that sells the approach: the guide implements a tiny effect handler for Log. When a script performs Log("Hello, world!"), the runner receives an UnhandledEffect, casts the payload to a string, prints it, and resumes execution with unit. Simple, clear, and safe. If your program never implements an effect, the interpreter surfaces it as an error — no surprise privileges. That model makes EYG attractive for Gleam apps that want powerful, composable scripting without handing users the keys to the kingdom.
Sources: github.com/crowdhailer, Lobsters
Comments