Skip to content
This repository was archived by the owner on Mar 14, 2026. It is now read-only.

Commit bee8a69

Browse files
koki-developclaude
andauthored
Add Rust 1.93.1 package (#38)
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 19a184f commit bee8a69

8 files changed

Lines changed: 195 additions & 166 deletions

File tree

AGENTS.md

Lines changed: 164 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
1+
# Repository Guideline
2+
3+
## Project Overview
4+
5+
Piston is a high-performance, high-security code execution engine supporting 90+ programming languages. It enables safe code execution via an API server and operates in a sandboxed environment using Linux Isolate (namespaces + chroot + cgroup).
6+
7+
## Development Commands
8+
9+
### Starting and Stopping the Environment
10+
11+
```bash
12+
./piston select dev # Select development environment (first time only)
13+
./piston start # Start
14+
./piston stop # Stop
15+
./piston restart # Restart
16+
./piston logs # Show logs
17+
./piston bash # Open container shell
18+
./piston rebuild # Build and restart
19+
```
20+
21+
### Code Formatting (Lint)
22+
23+
```bash
24+
./piston lint # Format all files with Prettier
25+
npx prettier --write <path> # Format specific files only
26+
```
27+
28+
### Package Management
29+
30+
```bash
31+
./piston list-pkgs # List available packages
32+
./piston build-pkg <pkg> <ver> # Build package
33+
./piston clean-pkgs # Clean build artifacts
34+
```
35+
36+
### CLI Setup
37+
38+
```bash
39+
cd cli && npm i && cd -
40+
```
41+
42+
## Architecture
43+
44+
```
45+
┌─────────────────────────────────────────────────────────────┐
46+
│ Docker Container │
47+
├─────────────────────────────────────────────────────────────┤
48+
│ api/ cli/ │
49+
│ ├─ Express Server ├─ yargs CLI │
50+
│ ├─ Routes (api/v2.js) └─ commands/ │
51+
│ ├─ Job Manager (job.js) ├─ execute.js │
52+
│ ├─ Runtime Manager └─ ppman.js │
53+
│ └─ Package Manager │
54+
├─────────────────────────────────────────────────────────────┤
55+
│ Isolate Sandbox │
56+
│ (Linux namespaces + chroot + cgroup) │
57+
├─────────────────────────────────────────────────────────────┤
58+
│ packages/ │
59+
│ └─ <lang>/<version>/ │
60+
│ ├─ metadata.json (language info, aliases) │
61+
│ ├─ build.sh (build script) │
62+
│ ├─ run (execution script) │
63+
│ └─ environment (environment variables) │
64+
└─────────────────────────────────────────────────────────────┘
65+
```
66+
67+
### Main Components
68+
69+
| File | Role |
70+
|---------|------|
71+
| `api/src/index.js` | Express server initialization |
72+
| `api/src/api/v2.js` | API endpoint definitions |
73+
| `api/src/job.js` | Job execution management (READY → PRIMED → EXECUTED) |
74+
| `api/src/runtime.js` | Language runtime management |
75+
| `api/src/package.js` | Package installation and management |
76+
| `api/src/config.js` | Configuration management via environment variables |
77+
78+
### API Endpoints
79+
80+
| Method | Path | Purpose |
81+
|---------|------|------|
82+
| GET | `/api/v2/runtimes` | List installed languages |
83+
| POST | `/api/v2/execute` | Execute code |
84+
| WebSocket | `/api/v2/connect` | Interactive execution |
85+
86+
## Configuration (Environment Variables)
87+
88+
Main environment variables (`PISTON_` prefix):
89+
90+
| Variable | Default | Description |
91+
|-----|---------|------|
92+
| `PISTON_LOG_LEVEL` | INFO | Log level |
93+
| `PISTON_BIND_ADDRESS` | 0.0.0.0:2000 | API bind address |
94+
| `PISTON_DISABLE_NETWORKING` | true | Disable networking |
95+
| `PISTON_COMPILE_TIMEOUT` | 10000 | Compile timeout (ms) |
96+
| `PISTON_RUN_TIMEOUT` | 3000 | Execution timeout (ms) |
97+
| `PISTON_MAX_PROCESS_COUNT` | 64 | Maximum process count |
98+
| `PISTON_OUTPUT_MAX_SIZE` | 1024 | Maximum output size |
99+
100+
See `docs/configuration.md` for details.
101+
102+
## Testing
103+
104+
Security tests are located in `/tests/`:
105+
106+
```bash
107+
python3 tests/fork.py # Fork bomb test
108+
python3 tests/fallocate.py # Disk fill attack test
109+
python3 tests/network.py # Network access test
110+
```
111+
112+
Package tests are automatically executed via GitHub Actions (`package-pr.yaml`).
113+
114+
## Adding Language Packages
115+
116+
1. Create `packages/<lang>/<version>/` directory
117+
2. Create required files:
118+
- `metadata.json` - Language name, version, aliases
119+
- `build.sh` - Build script
120+
- `run` - Execution script
121+
3. Build with `./piston build-pkg <lang> <version>`
122+
4. Add badge to README.md
123+
124+
## Code Style
125+
126+
Prettier configuration (`.prettierrc.yaml`):
127+
- Use single quotes
128+
- Tab width: 4
129+
- Omit arrow function parentheses
130+
131+
### Commit Messages
132+
133+
- **Do not use Conventional Commits** (no need for prefixes like `fix:`, `feat:`)
134+
- Write in normal format with concise description of changes
135+
136+
## GitHub Actions
137+
138+
### permissions Configuration
139+
140+
Workflows using ghcr.io or GitHub Releases require explicit permissions configuration:
141+
142+
```yaml
143+
jobs:
144+
job_name:
145+
runs-on: ubuntu-latest
146+
permissions:
147+
contents: write # When uploading to releases
148+
packages: write # When pushing to ghcr.io
149+
packages: read # When pulling from ghcr.io
150+
```
151+
152+
### Docker Image Workflows
153+
154+
| Workflow | Purpose | Trigger Path |
155+
|-------------|------|-------------|
156+
| `api-push.yaml` | API image | `api/**` |
157+
| `repo-push.yaml` | Repo Builder image | `repo/**` |
158+
| `package-push.yaml` | Package build | `packages/**` |
159+
160+
## Prerequisites
161+
162+
- Docker & Docker Compose
163+
- cgroup v2 enabled (cgroup v1 disabled)
164+
- Node.js >= 15 (for CLI development)

CLAUDE.md

Lines changed: 1 addition & 166 deletions
Original file line numberDiff line numberDiff line change
@@ -1,166 +1 @@
1-
# CLAUDE.md
2-
3-
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
4-
5-
## プロジェクト概要
6-
7-
Piston は、90以上のプログラミング言語をサポートする高性能・高セキュリティなコード実行エンジン。API サーバー経由でコードを安全に実行でき、Linux の Isolate (namespaces + chroot + cgroup) を使用したサンドボックス環境で動作する。
8-
9-
## 開発コマンド
10-
11-
### 環境の起動・停止
12-
13-
```bash
14-
./piston select dev # 開発環境を選択 (初回のみ)
15-
./piston start # 起動
16-
./piston stop # 停止
17-
./piston restart # 再起動
18-
./piston logs # ログ表示
19-
./piston bash # コンテナシェルを開く
20-
./piston rebuild # ビルドして再起動
21-
```
22-
23-
### コード整形 (Lint)
24-
25-
```bash
26-
./piston lint # Prettier で全ファイルをフォーマット
27-
npx prettier --write <path> # 特定ファイルのみフォーマット
28-
```
29-
30-
### パッケージ管理
31-
32-
```bash
33-
./piston list-pkgs # 利用可能なパッケージ一覧
34-
./piston build-pkg <pkg> <ver> # パッケージをビルド
35-
./piston clean-pkgs # ビルド成果物をクリーン
36-
```
37-
38-
### CLI のセットアップ
39-
40-
```bash
41-
cd cli && npm i && cd -
42-
```
43-
44-
## アーキテクチャ
45-
46-
```
47-
┌─────────────────────────────────────────────────────────────┐
48-
│ Docker Container │
49-
├─────────────────────────────────────────────────────────────┤
50-
│ api/ cli/ │
51-
│ ├─ Express Server ├─ yargs CLI │
52-
│ ├─ Routes (api/v2.js) └─ commands/ │
53-
│ ├─ Job Manager (job.js) ├─ execute.js │
54-
│ ├─ Runtime Manager └─ ppman.js │
55-
│ └─ Package Manager │
56-
├─────────────────────────────────────────────────────────────┤
57-
│ Isolate Sandbox │
58-
│ (Linux namespaces + chroot + cgroup) │
59-
├─────────────────────────────────────────────────────────────┤
60-
│ packages/ │
61-
│ └─ <lang>/<version>/ │
62-
│ ├─ metadata.json (言語情報、エイリアス) │
63-
│ ├─ build.sh (ビルドスクリプト) │
64-
│ ├─ run (実行スクリプト) │
65-
│ └─ environment (環境変数) │
66-
└─────────────────────────────────────────────────────────────┘
67-
```
68-
69-
### 主要コンポーネント
70-
71-
| ファイル | 役割 |
72-
|---------|------|
73-
| `api/src/index.js` | Express サーバー初期化 |
74-
| `api/src/api/v2.js` | API エンドポイント定義 |
75-
| `api/src/job.js` | ジョブ実行管理 (READY → PRIMED → EXECUTED) |
76-
| `api/src/runtime.js` | 言語ランタイム管理 |
77-
| `api/src/package.js` | パッケージのインストール・管理 |
78-
| `api/src/config.js` | 環境変数による設定管理 |
79-
80-
### API エンドポイント
81-
82-
| メソッド | パス | 目的 |
83-
|---------|------|------|
84-
| GET | `/api/v2/runtimes` | インストール済み言語一覧 |
85-
| POST | `/api/v2/execute` | コード実行 |
86-
| WebSocket | `/api/v2/connect` | インタラクティブ実行 |
87-
88-
## 設定 (環境変数)
89-
90-
主要な環境変数 (`PISTON_` プレフィックス):
91-
92-
| 変数 | デフォルト | 説明 |
93-
|-----|---------|------|
94-
| `PISTON_LOG_LEVEL` | INFO | ログレベル |
95-
| `PISTON_BIND_ADDRESS` | 0.0.0.0:2000 | API バインドアドレス |
96-
| `PISTON_DISABLE_NETWORKING` | true | ネットワーク無効化 |
97-
| `PISTON_COMPILE_TIMEOUT` | 10000 | コンパイルタイムアウト (ms) |
98-
| `PISTON_RUN_TIMEOUT` | 3000 | 実行タイムアウト (ms) |
99-
| `PISTON_MAX_PROCESS_COUNT` | 64 | 最大プロセス数 |
100-
| `PISTON_OUTPUT_MAX_SIZE` | 1024 | 出力最大サイズ |
101-
102-
詳細は `docs/configuration.md` を参照。
103-
104-
## テスト
105-
106-
セキュリティテストは `/tests/` にある:
107-
108-
```bash
109-
python3 tests/fork.py # フォーク爆弾テスト
110-
python3 tests/fallocate.py # ディスク満杯攻撃テスト
111-
python3 tests/network.py # ネットワークアクセステスト
112-
```
113-
114-
パッケージのテストは GitHub Actions (`package-pr.yaml`) で自動実行される。
115-
116-
## 言語パッケージの追加
117-
118-
1. `packages/<lang>/<version>/` ディレクトリを作成
119-
2. 必須ファイルを作成:
120-
- `metadata.json` - 言語名、バージョン、エイリアス
121-
- `build.sh` - ビルドスクリプト
122-
- `run` - 実行スクリプト
123-
3. `./piston build-pkg <lang> <version>` でビルド
124-
4. README.md にバッジを追加
125-
126-
## コードスタイル
127-
128-
Prettier 設定 (`.prettierrc.yaml`):
129-
- シングルクォート使用
130-
- タブ幅: 4
131-
- Arrow関数の括弧: 省略
132-
133-
### コミットメッセージ
134-
135-
- **Conventional Commits は使用しない** (`fix:`, `feat:` などのプレフィックスは不要)
136-
- 変更内容を簡潔に説明する通常の形式で記述
137-
138-
## GitHub Actions
139-
140-
### permissions 設定
141-
142-
ghcr.io や GitHub Releases を使用するワークフローでは、明示的な permissions 設定が必要:
143-
144-
```yaml
145-
jobs:
146-
job_name:
147-
runs-on: ubuntu-latest
148-
permissions:
149-
contents: write # リリースへのアップロード時
150-
packages: write # ghcr.io へのプッシュ時
151-
packages: read # ghcr.io からのプル時
152-
```
153-
154-
### Docker イメージワークフロー
155-
156-
| ワークフロー | 用途 | トリガーパス |
157-
|-------------|------|-------------|
158-
| `api-push.yaml` | API イメージ | `api/**` |
159-
| `repo-push.yaml` | Repo Builder イメージ | `repo/**` |
160-
| `package-push.yaml` | パッケージビルド | `packages/**` |
161-
162-
## 前提条件
163-
164-
- Docker & Docker Compose
165-
- cgroup v2 有効化 (cgroup v1 は無効化)
166-
- Node.js >= 15 (CLI 開発時)
1+
@AGENTS.md

packages/rust/1.93.1/build.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/usr/bin/env bash
2+
3+
curl -OL "https://static.rust-lang.org/dist/rust-1.93.1-x86_64-unknown-linux-gnu.tar.gz"
4+
tar xzvf rust-1.93.1-x86_64-unknown-linux-gnu.tar.gz
5+
rm rust-1.93.1-x86_64-unknown-linux-gnu.tar.gz

packages/rust/1.93.1/compile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/usr/bin/env bash
2+
3+
# https://stackoverflow.com/questions/38041331/rust-compiler-cant-find-crate-for-std
4+
# Rust compiler needs to find the stdlib to link against
5+
rustc -o binary -L ${RUST_INSTALL_LOC}/rustc/lib -L ${RUST_INSTALL_LOC}/rust-std-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib "$@"
6+
chmod +x binary

packages/rust/1.93.1/environment

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/usr/bin/env bash
2+
3+
# Put 'export' statements here for environment variables
4+
export PATH=$PWD/rust-1.93.1-x86_64-unknown-linux-gnu/rustc/bin/:$PATH
5+
export RUST_INSTALL_LOC=$PWD/rust-1.93.1-x86_64-unknown-linux-gnu

packages/rust/1.93.1/metadata.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"language": "rust",
3+
"version": "1.93.1",
4+
"aliases": [
5+
"rs"
6+
]
7+
}

packages/rust/1.93.1/run

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/usr/bin/env bash
2+
3+
shift
4+
./binary "$@"

packages/rust/1.93.1/test.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
fn main() {
2+
println!("OK");
3+
}

0 commit comments

Comments
 (0)