Sandboxes
I'm a big fan of interactive playgrounds. So today I'm open sourcing 30+ sandboxes — from programming languages to databases to networking and CLI tools. You can use them to experiment locally, or embed interactive examples in your writing like this:
// Java 23
void greet(String name) {
System.out.println("Hello, %s!".formatted(name));
}
void main() {
greet("World");
}
Hello, World!
Just look at this Java code, where did all that public-static-class stuff go? Is this even legal? :)
Or like this:
-- ClickHouse 24.8
create table data (id UInt32, x UInt32)
engine MergeTree order by id sample by id
as
select number+1 as id, randUniform(1, 100) as x
from numbers(10000);
select
avg(x) as "avg",
round(quantile(0.95)(x), 2) as p95
from data
sample 0.1;
┌─────avg─┬─p95─┐
│ 49.9294 │ 95 │
└─────────┴─────┘
Having a sampling feature in your SQL is really nice, isn't it?
What is a sandbox
Sandbox = image + box + commands:
- Image as a Docker image containing specific software, like a compiler or a database engine.
- Box is a configuration for running a container: cpu and memory restrictions, network, mounts, etc.
- Commands are predefined actions you can run in a container.
For example, here is a MariaDB sandbox:
mariadb.tar.gz
├── server
│ ├── Dockerfile
│ ├── database-create.sh
│ ├── database-drop.sh
│ └── init.sql
├── client
│ └── Dockerfile
├── box.json
├── commands.json
├── build.sh
└── setup.sh
You run sandboxes with Codapi (a lightweight sandbox server, essentially a thin layer on top of Docker/Podman).
To add a sandbox, run ./codapi-cli sandbox add <name>
like this:
./codapi-cli sandbox add lua
./codapi-cli sandbox add go
./codapi-cli sandbox add mariadb
...and you are good to go.
See github.com/nalgeon/sandboxes for details.
Supported languages and software
Programming languages:
Bash JavaScript Raku
C Kotlin Ruby
C# Lua Rust
C++ Odin TypeScript
Elixir PHP V
Go Python Zig
Java R
Databases:
chDB MySQL
ClickHouse PostgreSQL
DuckDB SQL Server
MariaDB SQLite
MongoDB
Networking and tools:
Caddy Grep ...and a ton of others
Curl Hurl
Git Ripgrep
Feel free to contribute new sandboxes or ask me to do so.
Final thoughts
Personally, I use these sandboxes all the time to write blog posts and interactive books. I hope you'll find them useful too!
See the nalgeon/sandboxes repo if you are interested.
★ Subscribe to keep up with new posts.