Tech Truth: Teaching Kids to Code with Sonic Pi • Sam Aaron & James Lewis • GOTO 2025
A deep dive with Sam Aaron, the creator of Sonic Pi, exploring his journey from early programming on a ZX Spectrum to creating a global platform for code-based music. The conversation covers the technical architecture of Sonic Pi, the critical role of Erlang's BEAM for concurrency, and the future direction with his new project, Tau5, which leverages AI for development and security testing.
The Journey to Code-Based Music
Sam Aaron’s introduction to programming began with a ZX Spectrum, which came with a manual that allowed him to teach himself BASIC. His initial explorations involved making beeps and drawing, which sparked his interest in the creative possibilities of code. Later, using a graphical calculator, he moved beyond plotting graphs to programming games, including a Pac-Man clone, turning the device into a makeshift games engine. This self-taught experience contrasted sharply with his formal computer science education at university, which he initially found uninspiring.
His interest in music was largely separate until an experience at a GOTO conference. Watching a “super band” of programmers perform, he had a realization: “If we’re all programmers, surely we should be able to program the music.” This idea led him down a rabbit hole of research, discovering the world of live coding and the powerful synthesis engine, SuperCollider.
Technical Foundations: From Ruby and Clojure to Sonic Pi
Initially, Sam attempted to build a music system in Ruby but quickly hit the limitations of its concurrency model. He recognized that music is inherently concurrent—like a band with multiple members playing simultaneously—and Ruby was ill-suited for the task.
A pivotal moment came when he saw Rich Hickey’s talk on Clojure, a Lisp dialect for the JVM. He was captivated by Hickey’s deep thinking on concurrency and expressivity. This inspired the Overtone project, a collaboration with Jeff Rose to combine SuperCollider with Clojure. Sam dedicated a year to developing Overtone, deepening his technical skills in functional programming and concurrency.
However, when the opportunity arose to build a tool for the Raspberry Pi, Clojure and the JVM proved too resource-intensive. With a tight deadline, he returned to Ruby, but with a new perspective. He implemented core concurrency primitives from Clojure, like promises, within Ruby to build the first version of Sonic Pi.
The Architecture of Sonic Pi: A Tale of Many Technologies
Sonic Pi is a complex system composed of several distinct processes, each chosen for its specific strengths:
- SuperCollider: The core synthesis engine.
- Ruby: The language runtime for the user-facing code.
- Erlang: Manages all I/O and orchestration, a choice influenced by Erlang’s creator, Joe Armstrong, who wrote the initial integration.
- C++: Used for MIDI and Ableton Link functionalities.
This distributed architecture, while powerful, created significant complexity. The need to boot, monitor, and tear down these processes correctly was a major engineering challenge.
The Power of Erlang and the BEAM
Sam speaks highly of Erlang’s concurrency model, which he considers superior to what’s available on the JVM. The key is that the BEAM virtual machine was built for the language’s concurrency model, not adapted to an existing one.
Key concepts of the Erlang philosophy include:
- “Let it Fail”: Instead of defensive coding, you write simple, single-threaded processes and let them crash.
- Supervisors: Other processes are responsible for monitoring these processes and restarting them if they fail. This “self-healing” capability is managed by the OTP (Open Telecom Platform) framework.
- Isolation: Processes share nothing, communicating only through messages. This prevents a crash in one process from affecting the rest of the system, unlike shared memory models.
Sam notes, “Any implementation of a concurrent system has a half-assed implementation of OTP.” Sonic Pi itself contains such an implementation, which motivated his next project.
The Future: Tau5 and AI
Sam’s new project, Tau5, aims to simplify Sonic Pi’s complex architecture by focusing purely on the BEAM. The goal is to retain the carefully designed language semantics of Sonic Pi but implement them on a more robust and simpler technological foundation.
He is also exploring the use of AI agents in the development of Tau5. His primary focus has been on security, creating a sandboxed environment safe for users to run untrusted code. He used an AI agent as a penetration tester to probe this sandbox for vulnerabilities. While the agent couldn’t escape the sandbox, it successfully launched denial-of-service attacks by consuming all CPU and memory, which allowed Sam to identify and fix these issues.
Code as a Modern Musical Score
A significant philosophical point is the idea of code as a durable musical score. Much of today’s electronic music is created by tweaking knobs and recording the output, leaving no reproducible artifact. Sam laments that there is “no score for Aphex Twin.”
By contrast, a composition written in Sonic Pi is a text-based artifact. It can be studied, modified, and preserved over time, much like the classical scores of Bach and Beethoven. This allows for a deeper understanding and ensures the work can survive changing technology. When asked about AI-generated music, Sam expressed more interest in AI generating a score that humans can then interpret, learn from, and modify, rather than just producing a final audio file.