Inspiration
Developers love sharing what they build, and reviewers, judges, and potential customers want to try an app live—not spend 20 minutes cloning a repository, debugging Python/Node versions, and fighting missing environment variables. Yet keeping always-on demo servers running costs money and breaks whenever dependencies drift.
PayToProvision solves both sides: paste any public GitHub repository, let AI figure out how to deploy it, and turn it into an ephemeral, pay-per-hour live preview environment powered by PayPal, NVIDIA Nemotron on Nebius, and Render.
What it does
PayToProvision creates a complete, autonomous marketplace for on-demand live software demos (using PayPal Sandbox):
- AI Repo Analyzer: An owner pastes a GitHub URL and sets an hourly rate and payout email. The analyzer inspects key repo files via the GitHub API and outputs a structured deploy plan (runtime, build/start commands,
$PORTbinding, env vars, health path, and confidence score). - Conversational AI Checkout Agent: Buyers can use standard PayPal JS SDK buttons or chat directly with an AI checkout agent ("What does this app do?" → "I'd like to try it for 2 hours"). The agent quotes the exact price and creates a PayPal order through the PayPal Agent Toolkit, handing the buyer an approval button.
- Ephemeral Live Previews on Render: Once payment is captured server-side, PayToProvision creates a private Render web service via the Render API and streams real-time build and boot progress with a live link and session countdown.
- AI Self-Healing & Automatic Refunds: If a deploy fails (e.g., a missing package like
requests), the AI Healer reads the build/runtime logs, proposes a safe config-only fix, and redeploys automatically (up to 2 attempts), logging everyold → newdiff on the session timeline. If the failure requires code changes or private packages, PayToProvision automatically issues a full PayPal Refund. - Automated Cleanup & Owner Payouts: When the session expires, a scheduled Reaper deletes the preview service on Render and sends the owner 80% of the session revenue via PayPal Payouts (retaining a 20% platform fee).
How we built it
- Backend & UI: Built with Python, FastAPI, SQLAlchemy 2, Alembic (SQLite for local dev, PostgreSQL in production), Jinja2, Tailwind CSS, and HTMX for live-updating session timelines without heavy client-side JS frameworks.
- AI Engine (
Nebius Token Factory+NVIDIA Nemotron 3 Super): Usesnvidia/nemotron-3-super-120b-a12bvia an OpenAI-compatible client with strict Pydantic JSON validation (auto-retrying once with validation feedback) across three workflows: repo analysis, log-based self-healing, and a custom tool-calling checkout loop. - PayPal Integration:
- Orders v2 & JS SDK: Server-side order creation and capture with idempotent
PayPal-Request-Idheaders. - PayPal Agent Toolkit: Uses
paypal-agent-toolkit(create_order,get_order_details) inside the checkout agent. - Webhooks, Refunds & Payouts: Verifies webhook signatures (
verify-webhook-signature), deduplicates stored event IDs, auto-refunds unfixable deploys, and pays owners with uniquesender_batch_idkeys.
- Orders v2 & JS SDK: Server-side order creation and capture with idempotent
- Pricing & Split Math: For an hourly listing price \(p\) and rented duration \(h\) hours (capped at 2 hours), the server computes the checkout total and revenue split deterministically: $$T = p \times h$$ $$F = \text{round}!\left(T \times \frac{20}{100},\, 2\right), \qquad N = T - F$$ where \(F\) is the 20% platform fee and \(N\) is the net payout sent to the repo owner.
- Infrastructure & Automation: Provisioned on Render via Blueprint (
render.yaml) and Terraform (infra/terraform), with a GitHub Actions cron hitting/internal/reapevery 15 minutes to clean up expired or orphanedptp-services.
Challenges we ran into
- Fitting the PayPal Agent Toolkit into a 512 MB instance: The toolkit's framework adapters (LangChain, CrewAI, OpenAI Agents SDK) pull in heavy dependency trees. We installed
paypal-agent-toolkit==1.11.0with--no-deps, wrapped its framework-agnosticPayPalAPI.runcore, and built a ~100-line tool-calling loop directly on the Nemotron API. - Preventing double captures, double payouts, and capacity races: Buyers might close their browser right after approving, or two buyers might race for the final preview slot. We funneled browser
onApprove, the return URL, andCHECKOUT.ORDER.APPROVEDwebhooks into a single idempotentcomplete_paymentfunction guarded by a capacity check before capturing funds. - Taming untrusted repos and logs (AI safety): Repo READMEs and app logs are untrusted data that can contain prompt injections or bad commands. We layered deterministic guardrails over every AI response:
- The checkout agent only passes integer
hours; the server always computes prices. - The repo analyzer enforces
0.0.0.0:$PORTbinding for Python servers. - The AI healer can only modify build/start commands, env vars, and health paths—and any command attempting file writes (
>,tee,sed -i,<<), script downloads (curl | sh), repo cloning, or recursive deletes is rejected.
- The checkout agent only passes integer
- Slow Render startup failures & server restarts: Apps failing health checks can stay "starting" for ~15 minutes on Render, so we added a 4-minute startup timeout to trigger healing/refunds faster and made provisioning re-entrant by state (
pending_payment → paid → deploying ⇄ healing → live → expired/failed_refunded) so the reaper resumes interrupted deploys after an app restart.
Accomplishments that we're proud of
- Building a true end-to-end agentic commerce + autonomous infrastructure loop: conversational checkout → PayPal payment → live cloud deployment → AI log healing → automatic refund or 80/20 PayPal payout.
- Giving users full transparency on the session page with a live event timeline showing every AI fix (
old → new), refund, and payout. - Shipping with a clean CI pipeline (
ruff, Alembic migration checks, 139 mockedpytesttests, andterraform validate).
What we learned
- LLMs work best behind deterministic guardrails: Pairing structured LLM outputs with Pydantic validation, strict state-machine transitions, server-side pricing, and command sanitization makes autonomous deployments and payments reliable.
- Idempotency everywhere: From PayPal order creation and webhook handling to Render cleanup and owner payouts, designing every step to be safely retriable turns partial failures into recoverable states.
What's next for PayToProvision
- Distributed database locks (e.g., Postgres advisory locks) to support multi-instance horizontal scaling.
- Live session extensions (top up extra hours before expiry) and custom subdomains for previews.
- Expanded runtime presets and pre-warmed build caches for faster cold-start previews across more languages.
Built With
- alembic
- fastapi
- github-actions
- htmx
- httpx
- jinja
- nebius
- nvidia-nemotron
- paypal
- paypal-agent-toolkit
- postgresql
- pydantic
- pytest
- python
- render
- sqlalchemy
- sqlite
- tailwindcss
- terraform
- uvicorn