Skip to content

Repository files navigation

Unsandbox

NPM Version

Hono と Node.js で実装された、Wandbox 互換の API サーバーおよび簡易 Web UI です。 ホストマシン上の gcc (C/C++) および rustc (Rust) を用いて、サンドボックスなしで直接コンパイル・実行します。


主な機能

  • Wandbox 互換 API:
    • GET /api/list.json: 利用可能なコンパイラの一覧および各コンパイラのオプションスイッチ・バージョン情報
    • POST /api/compile.json: コンパイル&実行を行い、結果(標準出力・標準エラー・終了コード・メッセージ)を JSON で返却
    • POST /api/compile.ndjson: コンパイル&実行ログをリアルタイムに NDJSON(New-line Delimited JSON)形式でストリーミング配信
    • GET /api/template/{template_name}: C, C++, Rust などのコードテンプレートを取得
    • POST /api/permlink & GET /api/permlink/{id}: コード・実行結果のパーマリンク作成・取得
    • GET /api/sponsors.json, GET /api/hpplib.json: Wandbox 互換スタブエンドポイント
  • 対応コンパイラ:
    • gcc (g++, gcc-cxx, cpp): GCC C++ Compiler (Boost / C++23 等対応)
    • gcc-c (c, gcc-head-c): GCC C Compiler (C11/C17/C2x 等対応)
    • rust (rustc): Rust Compiler
    • ※ コンパイラバージョンは環境の gcc --version / rustc --version から動的に取得されます。
  • Boost C++ ライブラリ対応:
    • boost (または boost-default) オプション指定でホストの Boost ライブラリを直接利用可能 (デフォルト有効)
  • マルチファイル対応:
    • codes: [{ file: "sub.h", code: "..." }, ...] で複数ファイルを指定可能
  • 簡易フロントエンド:
    • ルート (/) でモダンな Web UI を配信
    • 言語/コンパイラ選択
    • メインファイルおよびサブファイルの作成・削除・切り替えエディタ(Tab インデント対応)
    • コンパイラスイッチ・生オプション・標準入力 (stdin) 指定
    • NDJSON ストリーミングによるリアルタイム出力表示

必要環境とインストール方法

ホストマシン上で直接コンパイル・実行するため、事前に gcc (または g++)、boostrustcNode.js (v20 以上)、pnpm をインストールしてください。

1. ホスト環境のセットアップ

Ubuntu / Debian の場合

# GCC / G++ (ビルド必須ツール)
sudo apt update
sudo apt install -y build-essential

# Boost C++ ライブラリ (ヘッダーファイル)
sudo apt install -y libboost-dev

# Rust (rustc / cargo)
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
# または: sudo apt install -y rustc

# Node.js & pnpm
# (Node.js 20+ がインストールされている状態で)
npm install -g pnpm

macOS (Homebrew) の場合

# Command Line Tools (Clang / C++ コンパイラ) または GCC
xcode-select --install
# (必要に応じて Homebrew GCC を利用する場合: brew install gcc)

# Boost C++ ライブラリ
brew install boost
# ※ Apple Silicon Mac (/opt/homebrew/opt/boost/include 等) および
#    Intel Mac (/usr/local/opt/boost/include 等) の両インクルードパスに自動対応しています。

# Rust (rustc / cargo)
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
# または: brew install rust

# Node.js & pnpm
brew install node pnpm

サーバーの起動方法

1. npx で即座に実行(インストール不要)

npx unsandbox

ポートやホストを指定する場合:

npx unsandbox --port 8080 --host 0.0.0.0

2. ソースコードからビルド・起動

# 依存関係インストール
pnpm install

# 開発サーバー起動 (ファイル変更時自動リロード)
pnpm dev

# 本番ビルド & 起動
pnpm build
pnpm start

# テスト実行
pnpm test

npm へのパッケージ公開 (Publish)

本パッケージは pnpm publish で npm レジストリに公開可能です。

# ログイン(初回のみ)
pnpm login

# ビルド & テストが自動実行されて公開されます (prepublishOnly)
pnpm publish --access public

ライセンス

本ソフトウェアは MIT License のもとで公開されています。

謝辞 / クレジット

本プロジェクトは melpon 氏によって作成された Wandbox (Boost Software License 1.0) の API 仕様および UI 設計を参考にしています。


API 使用例

1. コンパイラ一覧の取得 (/api/list.json)

curl http://localhost:3000/api/list.json

2. コードのコンパイルと実行 (/api/compile.json)

curl -X POST http://localhost:3000/api/compile.json \
  -H "Content-Type: application/json" \
  -d '{
    "compiler": "gcc",
    "code": "#include <stdio.h>\nint main() { printf(\"Hello, Unsandbox!\\n\"); return 0; }",
    "options": "warning,c17"
  }'

レスポンス例:

{
  "status": "0",
  "signal": "",
  "compiler_output": "",
  "compiler_error": "",
  "compiler_message": "",
  "program_output": "Hello, Unsandbox!\n",
  "program_error": "",
  "program_message": "Hello, Unsandbox!\n"
}

3. ストリーミング実行 (/api/compile.ndjson)

curl -X POST http://localhost:3000/api/compile.ndjson \
  -H "Content-Type: application/json" \
  -d '{
    "compiler": "rustc",
    "code": "fn main() { println!(\"Streaming Rust execution!\"); }"
  }'

レスポンス例:

{"type":"Control","data":"Start"}
{"type":"StdOut","data":"Streaming Rust execution!\n"}
{"type":"ExitCode","data":"0"}
{"type":"Control","data":"Finish"}

About

Wandbox-compatible API server that runs directly on the host

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages