Reference
Best Practices
Project setup
- Always add
requires:for the services you use. The platform only injects environment variables for declared dependencies. - Use
grid devinstead of managing local databases. It provides isolated sandboxes with real data and automatic teardown. - Keep
cloudgrid.yamlin your repo root. It is portable (no identity, no secrets) and safe to commit. .cloudgrid/is auto-added to.gitignore. Never commit it. Forks and clones start unlinked intentionally.
Deployment
- Run
grid devand test locally before runninggrid plug. - Use
grid plug --detachfor long builds so you can continue working. - Use
grid follow <trace_id>to re-attach to detached deploys. - Use
grid rollbackif a deploy introduces issues. It re-points at the previous image instantly. - Wire your GitHub repo (
grid wire repo) for automatic deploys on push.
Security
- Use
grid secrets setfor API keys, tokens, and connection strings. Never put secrets incloudgrid.yamlor env vars. - Use
vault:incloudgrid.yamlfor external database connection strings. - Set visibility to
privateororgunless you explicitly want public access. - Use
callers:to control which entities can call yours. Default policy ismanualwithdenyfallback.
Collaboration
- Use spaces to organize entities by team, project, or purpose.
- Set appropriate visibility for each entity.
orgis the safest default for internal tools. - Use
grid forkwhen you want to build on someone else’s work while maintaining lineage. - Use
grid clonewhen you want to take over an existing entity on a new machine.
Multi-service architecture
- Keep services focused. One service per concern (API, frontend, worker, cron).
- Use
path:to route traffic to the right service. Setpath: falsefor internal-only services. - Deploy order is automatic — when no service declares
depends_on:, the platform sequences data stores → backend → frontend on first deploy and waits for each stage to be healthy. Declaredepends_on:to control it yourself, or setdeploy_order: offto disable. - Use
calls:andcallers:for cross-entity communication instead of hardcoding URLs.
AI Gateway
- Declare
requires: [ai]and use@cloudgrid-io/runtime(runtime.ai.*) instead of calling Claude or OpenAI directly. The gateway handles identity, metering, budgeting, and the per-Grid provider decision. - Use
claude-haikufor high-volume, low-latency tasks. Useclaude-sonnetas the default. Useclaude-opusfor tasks that need the highest capability. - Handle
AI_BUDGET_EXCEEDEDerrors gracefully. The gateway enforces per-entity monthly token caps.
Agents
- Start as an app, add the
agent:block when you need scheduled autonomous behavior. - Set
hard_stop: trueon the budget to prevent runaway token spend. - Use the
memoryblock to persist agent state across runs.