Skip to content

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

Β 

History

2 Commits

Folders and files

Repository files navigation

TryCode.run - Online Code Runner

A full-stack online code execution platform supporting 30+ programming languages with WASM-first execution, intelligent fallback, real-time collaboration, and comprehensive admin panel.

πŸ—οΈ Architecture Overview

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                           TryCode.run Architecture                            β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚                                                                              β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”‚
β”‚  β”‚   Frontend   │────▢│    Backend API      │────▢│   Executor Pool     β”‚  β”‚
β”‚  β”‚  (React+Vite)β”‚     β”‚    (Rust+Axum)      β”‚     β”‚   (2x gVisor)       β”‚  β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜     β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜     β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β”‚
β”‚         β”‚                      β”‚                        β”‚                   β”‚
β”‚         β–Ό                      β–Ό                        β–Ό                   β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”‚
β”‚  β”‚   Monaco     β”‚     β”‚  PostgreSQL + Redis β”‚     β”‚  Debian 12 + 30     β”‚  β”‚
β”‚  β”‚   Editor +   β”‚     β”‚  (1panel-network)   β”‚     β”‚  Languages + gVisor β”‚  β”‚
β”‚  β”‚   Yjs Collab β”‚     β”‚                     β”‚     β”‚                     β”‚  β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜     β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜     β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β”‚
β”‚                                                                              β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”   β”‚
β”‚  β”‚                    Observability Stack (VictoriaLogs + VictoriaMetrics)β”‚   β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜   β”‚
β”‚                                                                              β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

✨ Features

πŸš€ Multi-Language Execution (30+ Languages)

  • Tier 1 (WASM-native): Python (Pyodide), JavaScript/TypeScript (QuickJS), HTML/CSS/JS (Browser), Rust (wasmer), Lua, SQL
  • Tier 2 (Native compiled): Go, Rust, C/C++, Java, C#, PHP, Ruby, Swift, Kotlin, Scala, R, Dart, Zig, Julia, Haskell, Fortran, Objective-C, VB.NET, F#, Groovy
  • Tier 3 (Shell): Bash, PowerShell, SQL

⚑ Smart WASM-First Execution

  • 5-second timeout for WASM execution in browser
  • Automatic fallback to backend on timeout, OOM, missing runtime, compile errors
  • Preloading of common language runtimes (Python, JS, TS)
  • Resource quotas per user/language (CPU time, memory, disk, wall time)

🀝 Real-time Collaboration

  • Yjs CRDT for conflict-free concurrent editing
  • WebSocket awareness (cursors, selections, user presence)
  • Permission system: Owner, Editor, Viewer roles
  • Persistence to PostgreSQL with incremental sync

πŸ” Authentication & Security

  • JWT (15min access + 30d refresh, HttpOnly cookies)
  • Argon2id password hashing (configurable parameters)
  • Email verification with 6-digit codes
  • CAPTCHA (trycap.dev self-hosted, Turnstile/hCaptcha/reCAPTCHA fallback)
  • GitHub OAuth with domain restrictions
  • Rate limiting (IP, user, API key tiers)
  • gVisor (ptrace platform) for strong sandbox isolation

πŸ“Š Admin Panel

  • System monitoring: Users, executions, success rates, language stats
  • User management: Roles, status, locking, execution quotas
  • Execution logs: Filtering, WASM fallback tracking
  • Dynamic config: Hot-reload via PostgreSQL NOTIFY
  • System tests: SMTP, CAPTCHA, OAuth, Database
  • Audit logs: All admin actions tracked

πŸ“ Project Management

  • Virtual filesystem with folders, files, rename, move, delete
  • Sharing: Time-limited, password-protected, permission-controlled links
  • Forking: Full project copy with history
  • Templates: Language-specific starter templates

πŸ€– AI Assistant (OpenAI-compatible)

  • Code explanation (brief/standard/detailed)
  • Code review (security, performance, readability, bugs)
  • Test generation (pytest, jest, cargo test, etc.)
  • Chat with code context
  • Configurable endpoint, model, temperature

🐳 Deployment (3 Containers)

# docker-compose.yml - 3 services only!
services:
  backend:        # Rust API + VictoriaMetrics + VictoriaLogs + Vector (s6-overlay)
  exec-worker-1:  # Debian 12 + 30 languages + gVisor
  exec-worker-2:  # Debian 12 + 30 languages + gVisor

External dependencies (on 1panel-network):

  • PostgreSQL (pgdocker:5432)
  • Redis (redisdocker:6379)

Resource budget (4 CPU cores):

Container CPU Memory
backend 1.5 cores 1.5 GB
exec-worker-1 1.0 core 768 MB
exec-worker-2 1.0 core 768 MB

πŸš€ Quick Start

Prerequisites

  • Docker & Docker Compose
  • PostgreSQL & Redis (on 1panel-network)
  • Domain with SSL (OpenResty terminates TLS)

1. Initialize Secrets

# On server (run once)
sudo systemctl start trycode-init-secrets
# Or manually:
mkdir -p /opt/trycode/secrets
openssl rand -hex 32 > /opt/trycode/secrets/jwt_secret.txt
openssl rand -hex 24 > /opt/trycode/secrets/pg_password.txt
# ... etc (see scripts/init-secrets.sh)

2. Configure

cp /opt/trycode/config/backend.toml.example /opt/trycode/config/backend.toml
# Edit with your SMTP, CAPTCHA, OAuth, AI settings

3. Deploy

cd /opt/trycode
TAG=v1.0.0 docker compose pull
TAG=v1.0.0 docker compose up -d --remove-orphans

4. Initialize Super Admin

# Visit https://trycode.run/admin
# First visit creates super admin account

πŸ“ Project Structure

trycode.run/
β”œβ”€β”€ docker-compose.yml              # 3-container orchestration
β”œβ”€β”€ config/
β”‚   β”œβ”€β”€ backend.toml                # Backend config (hot-reload)
β”‚   β”œβ”€β”€ vector.toml                 # Vector log collector config
β”‚   β”œβ”€β”€ vm-scrape.yml               # VictoriaMetrics scrape config
β”‚   └── trycode.run.conf            # OpenResty template
β”œβ”€β”€ backend/
β”‚   β”œβ”€β”€ Cargo.toml                  # Rust workspace
β”‚   β”œβ”€β”€ Dockerfile.all-in-one       # s6-overlay multi-process image
β”‚   β”œβ”€β”€ migrations/                 # SQLx migrations (PostgreSQL)
β”‚   β”œβ”€β”€ trycode-backend/            # Main binary
β”‚   β”œβ”€β”€ trycode-core/               # Shared config, DB, metrics
β”‚   β”œβ”€β”€ trycode-auth/               # JWT, Argon2id, CAPTCHA, OAuth
β”‚   β”œβ”€β”€ trycode-execution/          # Queue, scheduler, gVisor, limits
β”‚   β”œβ”€β”€ trycode-collab/             # Yjs WebSocket broker
β”‚   β”œβ”€β”€ trycode-projects/           # Projects, files, sharing
β”‚   β”œβ”€β”€ trycode-admin/              # Admin panel, config, tests
β”‚   └── trycode-ai/                 # AI gateway (OpenAI-compatible)
β”œβ”€β”€ executor/
β”‚   β”œβ”€β”€ Dockerfile                  # Debian 12 + 30 langs + gVisor
β”‚   β”œβ”€β”€ entrypoint.sh               # Metrics exporter entrypoint
β”‚   └── Cargo.toml                  # Executor daemon (metrics)
β”œβ”€β”€ frontend/
β”‚   β”œβ”€β”€ package.json                # React + Vite + TS
β”‚   β”œβ”€β”€ vite.config.ts
β”‚   β”œβ”€β”€ tailwind.config.js
β”‚   └── src/
β”‚       β”œβ”€β”€ components/             # Editor, Terminal, FileTree, Collab, AI
β”‚       β”œβ”€β”€ pages/                  # Editor, Project, Auth, Admin, Share
β”‚       β”œβ”€β”€ hooks/                  # useAuth, useTheme, useCollab
β”‚       β”œβ”€β”€ stores/                 # Zustand (editor, execution, UI)
β”‚       └── utils/                  # API client, language config
β”œβ”€β”€ scripts/
β”‚   β”œβ”€β”€ init-secrets.sh             # Secret generator
β”‚   └── trycode-init-secrets.service # systemd oneshot
β”œβ”€β”€ .github/workflows/              # CI/CD (build, test, deploy)
└── README.md

πŸ”§ Configuration

Backend (config/backend.toml)

[server]
host = "0.0.0.0"
port = 3000

[database]
url = "postgres://trycode:pass@pgdocker:5432/trycode"

[redis]
host = "redisdocker"
port = 6379

[smtp]
host = "smtp.example.com"
port = 587
username = "noreply@trycode.run"
password = "secret"  # From Docker Secret
from = "TryCode <noreply@trycode.run>"
tls = "starttls"

[captcha]
provider = "trycap"
site_key = "your-site-key"
secret_key = "secret"  # From Docker Secret
verify_url = "http://trycap:8080/api/v1/verify"
enabled = true
actions = ["register", "login", "execute"]

[oauth.github]
enabled = true
client_id = "github-client-id"
client_secret = "secret"  # From Docker Secret
redirect_url = "https://trycode.run/api/auth/oauth/github/callback"

[ai]
enabled = true
base_url = "https://api.openai.com/v1"
api_key = "sk-..."  # From Docker Secret
default_model = "gpt-4o-mini"

[execution]
global_max_concurrent = 4
per_user_max_concurrent = 2
queue_timeout_secs = 60
default_cpu_time_secs = 30
default_memory_mb = 256

Frontend (.env)

VITE_API_BASE=/api
VITE_WS_BASE=ws://localhost:3000

πŸ§ͺ Development

Backend

cd backend
cargo test --workspace
cargo run --bin trycode-backend serve

Frontend

cd frontend
npm install
npm run dev
# http://localhost:5173

Full Stack (Docker Compose)

docker compose -f docker-compose.yml up -d
# Backend: http://localhost:3000
# Frontend: http://localhost:5173 (dev)
# Metrics: http://localhost:8428
# Logs: http://localhost:9428

πŸ“Š Monitoring

  • Metrics: VictoriaMetrics at :8428 (PromQL, 30d retention)
  • Logs: VictoriaLogs at :9428 (LogSQL, 7d/30d retention)
  • Vector collects Docker logs β†’ VictoriaLogs
  • Health: GET /health (checks PG, Redis, VM, VL, executors)

πŸ”’ Security Hardening

  • gVisor ptrace platform (kernel 7.x compatible)
  • No network in execution containers (network_mode: none)
  • Read-only rootfs, tmpfs for workspace
  • Resource limits: CPU, memory, pids, disk
  • Secrets: Docker Secrets (JWT, DB, SMTP, CAPTCHA, AI, OAuth)
  • Rate limiting: Per-IP, per-user, per-API-key
  • CSP, HSTS, X-Frame-Options via OpenResty

πŸ“ License

MIT License - see LICENSE file for details.

🀝 Contributing

  1. Fork the repository
  2. Create feature branch
  3. Run tests: cargo test --workspace / npm test
  4. Submit PR

πŸ“ž Support

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages