Enable Ruby in Docker Sandboxes

Docker Sandboxes are minimal virtual environments, so if you want to use Ruby, you need to install it separately within the sandbox.

Installation

Choose the sandbox where you want to install Ruby.

$ sbx ls

Log in to the target sandbox

$ sbx exec -it [sandbox name] bash

Install required libraries within the sandbox

$ sudo apt update
$ sudo apt install -y \
    git curl build-essential \
    libssl-dev libreadline-dev zlib1g-dev \
    libyaml-dev libffi-dev libgdbm-dev \
    libncurses-dev libdb-dev uuid-dev

Install rbenv

git clone https://github.com/rbenv/rbenv.git ~/.rbenv
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc
echo 'eval "$(rbenv init - bash)"' >> ~/.bashrc

Load the configuration

$ source ~/.bashrc

Install ruby-build

$ git clone https://github.com/rbenv/ruby-build.git "$(rbenv root)"/plugins/ruby-build

Check available Ruby versions

$ rbenv install --list

Install version 4.0.5 in this example.

$ rbenv install 4.0.5

After a successful installation without errors, it’s complete.
Specify the Ruby version to use by default.

rbenv global 4.0.5
rbenv rehash

Environment Variable Setup

So far, this is similar to installing Ruby normally, but when using Docker Sandboxes, you need an additional step.

Use the following command to set the same environment variables in /etc/sandbox-persistent.sh.

cat <<'EOF' | sudo tee -a /etc/sandbox-persistent.sh
export RBENV_ROOT="$HOME/.rbenv"
export PATH="$RBENV_ROOT/bin:$RBENV_ROOT/shims:$PATH"
EOF

When starting the sandbox with an agent, ~/.bashrc is not loaded, so even if you set environment variables, they won’t take effect. To resolve this, you need to write them in /etc/sandbox-persistent.sh.

From the next time onward, when you run

$ sbx run opencode

Ruby will be available in the environment.

© 2025 Hiroe Tech Notes. All rights reserved.

Comments

No comments yet.