bopjesvla
Sand: an Elixir sandbox
I’m very excited to share this!
Sand is a language-level Elixir sandbox. It’s fast and very much experimental. It uses max_heap_size to limit memory usage, reduction monitoring to limit CPU usage, and AST whitelisting to make sure all code is nice and side-effectless. Atom renaming is used to combat the atom table filling up, and binaries are limited to 64 bytes to make sure nothing is stored off-heap.
The demo can be found here.The code can be found here. I’m very curious to see if you guys can manage to break out of this thing!
Most Liked
bopjesvla
So I’m not aiming to create something that can run existing Elixir projects, just something that allows users to program select parts of websites.
bopjesvla
That’s a good question. It should be noted that this limitation is one-directional. You can run Sand code in Elixir if you import the macro r (and, in the future, possibly load).
An example use case would be allowing untrusted users to run bots on chat site, without using a lot of server resources. The server provides user messages to the sandbox and sends the sandbox output back to the chat.
The reason why you’d use this over existing (OS-level) sandbox solutions is that it doesn’t require additional moving parts (just one dependency) and because of the speed and low overhead.
bopjesvla
That’s by design, you only get a small share of RAM.
I will update the error message to make this more clear.
bopjesvla
Done!
On the demo server, I’ve given each program a generous 1 MB of memory. This is configurable, so more computationally heavy stuff could also be run in the sandbox.
Phillipp
Nice.
The highest number I can use in the demo is factorial.(866). It breaks with 867 and above.







