We needed a way for students to write and submit code directly inside Moodle quizzes — with instant, automated grading. The answer was CodeRunner with a distributed Jobe sandbox running across our Docker Swarm. The LMS is live at ftds.online.
Architecture
Moodle runs on a DigitalOcean VPS. When a student
submits code, CodeRunner sends the job to
jobe.ftds.online, which tunnels into our
on-premise Docker Swarm via frp.
HAProxy load-balances across Jobe instances — one
per swarm node.
Students → ftds.online (DigitalOcean VPS)
├── ftds.online → Moodle / Apache
└── jobe.ftds.online → frp tunnel
↓
HAProxy LB
↓
Jobe instances (1 per swarm node)
- Moodle + Apache — hosted on a VPS, serves the LMS frontend
- Jobe (jobeinabox) — code execution sandbox, runs globally across all swarm nodes
-
HAProxy — load balancer with
health checks (
inter 10s,fall 5,rise 2) -
frp tunnel — Docker Swarm
service exposing the LB to Moodle via
jobe.ftds.online
Setting Up the Swarm
All nodes must be on the same subnet. We set up routers in AP mode so every device shares the same IP range, then bootstrapped each node with a script:
# On the leader — initialize Docker Swarm
docker swarm init --advertise-addr 10.0.190.70:2377
# On each worker — fill in .env with token and leader IP, then:
sudo ./swarm
The swarm script handles Docker
installation (Ubuntu/Arch), user permissions, and
joining the Swarm cluster automatically.
Deploying the Stack
With the swarm ready, we deploy three services: Jobe instances (one per node), HAProxy for load balancing, and an frp tunnel to expose the cluster to the Moodle VPS.
# Import configs
docker config create haproxy_cfg ./haproxy.cfg
docker config create frpc_cfg ./frpc.cfg
# Deploy CodeRunner stack
docker stack deploy -c stack.yml coderunner
# Deploy Portainer for monitoring
docker stack deploy -c portainer-agent-stack.yml portainer
# Verify
docker stack ps coderunner
Portainer gives us a web UI at port 9000 to monitor node health, container status, and cluster visualization across all swarm nodes.
The frp Tunnel
Since the swarm runs on-premise behind NAT, we use
frp to
create a reverse tunnel from the Moodle VPS to the
swarm. The VPS runs frps listening on port
7000, and the swarm leader runs frpc as a
Docker service:
# frpc.toml (on swarm leader, runs as Docker service)
serverAddr = "ftds.online"
serverPort = 7000
auth.token = "..."
[[proxies]]
name = "jobe_tunnel"
type = "http"
localIP = "lb" # resolves on Docker overlay network
localPort = 80
customDomains = ["jobe.ftds.online"]
On the VPS side, Apache proxies
jobe.ftds.online to the frp listener on
port 8080:
# /etc/apache2/sites-available/jobe.conf
<VirtualHost *:80>
ServerName jobe.ftds.online
ProxyPreserveHost On
ProxyPass / http://127.0.0.1:8080/
ProxyPassReverse / http://127.0.0.1:8080/
</VirtualHost>
SQL Support with sqlglot
We built a custom Jobe image that includes
sqlglot
for SQL transpilation. Students can write SQL in MySQL
or T-SQL syntax, and the sandbox transparently
transpiles it to SQLite before execution. This lets us
use the lightweight
AdventureWorksLT database (converted
from SQL Server .bak to SQLite) without
running a full database server.
# Build custom Jobe image with sqlglot
docker build -t ${REGISTRY}/jobe-sqlglot:latest ./jobe
docker push ${REGISTRY}/jobe-sqlglot:latest
# Deploy
docker stack deploy -c docker-compose.yml coderunner
The CodeRunner template uses
sqlglot.transpile(sql, read="tsql",
write="sqlite")
to handle T-SQL syntax like TOP 5,
ISNULL(), and square bracket identifiers.
Course Management
We wrote a shell script to clone courses for new semesters — copying activities, quizzes, question banks, and resources while stripping out student data:
# Clone a course for a new semester
./scripts/clone-course.sh 8 "TIN313(2627-1)GD1.01" \
"TIN313(2627-1)GD1.01 - CO SO DU LIEU - Minh" "2026-09-01"
Repo Structure
ftulabs/coderunner # Swarm bootstrap scripts
├── swarm # Node bootstrap (Docker + Swarm join)
├── swarm.ps1 # Windows variant
├── allow-ports # Firewall rules
├── stack.yml # Docker stack (Jobe + HAProxy + frpc)
└── haproxy.cfg # Load balancer config
ftulabs/moodle-coderunner # Moodle integration
├── docker-compose.yml # Swarm stack (Jobe + HAProxy + tunnel)
├── jobe/
│ ├── Dockerfile # Custom Jobe image (base + sqlglot)
│ └── haproxy.cfg # HAProxy config
├── scripts/
│ ├── clone-course.sh # Course cloning
│ └── clone-course.php # Moodle backup/restore
└── adventureworks/
├── AdventureWorksLT2019.db
└── sql_quizzes.xml # Quiz questions (Moodle XML)
Links
- ftds.online — live LMS
- ftulabs/coderunner — Swarm bootstrap scripts
- ftulabs/moodle-coderunner — Moodle CodeRunner deployment and course tools