Fundamentals 6 min read

What’s New in Ruby 4.0? Exploring Box Isolation, ZJIT, and Ractor Enhancements

Ruby 4.0, released on December 25 to mark the language’s 30th anniversary, introduces experimental Box isolation, the ZJIT compiler, and a revamped Ractor for concurrency, but many features remain immature and optional for production use.

21CTO
21CTO
21CTO
What’s New in Ruby 4.0? Exploring Box Isolation, ZJIT, and Ractor Enhancements

Ruby 4.0 Release Overview

Ruby 4.0 was released on 25 December 2025, marking the language’s 30‑year anniversary. The release introduces three experimental features that target isolation, just‑in‑time compilation, and concurrency.

Experimental Isolation – Ruby Box

Ruby Box is a sandboxing mechanism that can isolate classes, modules, instance variables, and global variables inside a dedicated Box object. The feature is disabled by default and can be turned on with the environment variable RUBY_BOX=1 (or by setting RUBYOPT="-rbox" in some setups). When enabled, each Box creates a separate namespace, allowing multiple versions of the same library to coexist within a single process.

# Example: enabling Ruby Box from the shell
export RUBY_BOX=1
ruby -e "box = Ruby::Box.new { class Foo; def self.greet; puts 'inside box'; end; end }; Foo.greet"

Because the implementation is still experimental, developers have reported that its isolation semantics are less mature than similar solutions in JRuby, TruffleRuby, or V8.

Just‑In‑Time Compiler – ZJIT

ZJIT is a new JIT compiler added in Ruby 4.0. It is also off by default and can be enabled with RUBY_ZJIT=1. The compiler team states that ZJIT is faster than the traditional interpreter but slower than the existing YJIT implementation. They also warn that enabling ZJIT may lead to crashes or significant performance regressions in some workloads.

# Enable ZJIT for a single run
RUBY_ZJIT=1 ruby my_script.rb

Concurrency – Ractor Improvements

Ractor, introduced in Ruby 3.0, provides an actor‑style concurrency model where each Ractor runs with its own Global VM Lock (GVL). In Ruby 4.0 the following enhancements were made:

Internal data structures were refactored for lower contention.

A new helper class was added to address message‑passing edge cases.

Documentation now clarifies that the feature remains experimental, with a target of production‑ready status around 2026.

Developers can create a Ractor as follows:

r = Ractor.new do
  10.times { puts "hello from ractor" }
end
r.take # wait for completion

Adoption Landscape

According to the latest Stack Overflow Developer Survey, only about 6.9 % of professional developers report using Ruby. The language’s usage is tightly coupled with the Rails framework, which powers large platforms such as Shopify and GitHub.

Community Feedback and Caveats

Some users consider Ruby Box’s isolation model immature compared to alternatives in other Ruby implementations.

There is criticism that Ruby often ships features that are not yet ready for production, a sentiment echoed for both Box and Ractor.

ZJIT’s optional nature mitigates risk, but developers should benchmark their workloads before enabling it in production.

Overall, Ruby 4.0 delivers notable advances in isolation and concurrency, but the experimental status of its new features means that only a subset is advisable for production use at this time.

concurrencyJITisolationRubyLanguageFeaturesRuby4.0
21CTO
Written by

21CTO

21CTO (21CTO.com) offers developers community, training, and services, making it your go‑to learning and service platform.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.