plaize Sandbox 基盤の Python (FastAPI) アプリ向けテンプレート。 データ保存(Notion / Firestore)や API 呼び出し等が必要なアプリで使う。
静的 HTML だけで足りる場合は
sandbox-template-staticを使ってください。
| ファイル | 役割 |
|---|---|
main.py |
FastAPI アプリ本体(Hello world)。ここを書き換えていく |
requirements.txt |
依存ライブラリ |
Dockerfile |
Cloud Run 用イメージ定義 |
sandbox.yaml |
アプリのメタデータ(必須) |
sdks/notion_db.py |
Notion API クライアント(軽量) |
sdks/sandbox_db.py |
Firestore ラッパ(apps/{owner}--{app}/... に自動 prefix) |
build/validate-sandbox.py |
CI で sandbox.yaml を検証 |
.github/workflows/deploy.yml |
push → Cloud Run 自動デプロイ |
- Claude Desktop で
sandbox_newツールに「Python テンプレで作って」と頼む - テンプレが clone され、
sandbox.yamlに owner / app / name / purpose が入る main.pyを Claude に書いてもらうgit push→ 2分後にhttps://<owner>--<app>.sandbox.plaize.coで開ける
sandbox.yamlに追記:data: notion: - id: "<Notion DB の ID>" access: "read-write" # or "read"
- Notion 側で Integration を作って DB に Connect(Phase 2 で自動化予定、当面手動)
- Integration の token を Secret Manager に保管:
echo -n "<secret_xxx>" | gcloud secrets create \ app--<owner>--<app>--notion-token --data-file=- \ --project=plaize-sandbox-prod # 自分の per-app SA に読み取り権限: gcloud secrets add-iam-policy-binding \ app--<owner>--<app>--notion-token \ --member="serviceAccount:app-<owner>-<app>@plaize-sandbox-prod.iam.gserviceaccount.com" \ --role="roles/secretmanager.secretAccessor"
main.pyで使う:from sdks.notion_db import client n = client() # NOTION_TOKEN env から自動取得 rows = n.query(os.environ["NOTION_DB_CUSTOMER"])
sandbox.yamlに追記:data: firestore: true
requirements.txtでgoogle-cloud-firestore==2.18.0のコメント外しmain.pyで使う:from sdks.sandbox_db import client db = client() # apps/<owner>--<app>/... に自動 prefix db.collection("notes").add({"text": "hello"})
⚠️ Phase 2 では Firestore named DBsandboxと per-app SA の IAM condition で 別アプリのデータが見えないよう保護される予定。まだ Phase 2 セットアップ前は Firestore は本格的に使わないこと
pip install -r requirements.txt
SANDBOX_OWNER=urara SANDBOX_APP=hello-py uvicorn main:app --reload --port 8080→ http://localhost:8080 で Hello ページが見える(ただし sandbox-router の認証は通らない)
git push origin main → GitHub Actions が走り、約2分で Cloud Run に反映。
https://<owner>--<app>.sandbox.plaize.co で動作確認。
sandbox.yaml の owner フィールドが自分自身のとき、このアプリのコードを編集する権利がある(CODEOWNERS と PR レビューで担保予定)。