Inspiration

Freelance work runs on trust, and on small jobs neither side has much of it. Clients worry about paying for work that is broken or never arrives. Freelancers worry about doing the work and never getting paid. Escrow fixes the money part, but somebody still has to decide whether the work is actually correct, and that is slow, manual and often turns into an argument. I wanted to see if PayPal plus AI could make an escrow that decides based on evidence.

What it does

TrustAgent AI holds a client's money in PayPal and releases it only when the work is proven to work.

  1. The client defines a milestone and funds the escrow through PayPal.
  2. The freelancer submits a Python function.
  3. Gemini writes hidden tests and the app runs the freelancer's code against them.
  4. If the code passes, PayPal pays the freelancer automatically. If it fails, the money stays held, and the client can take a PayPal refund.

Every step is recorded in a timestamped escrow ledger.

How I built it

  • PayPal (the core): Orders API to create and capture the client's payment, Payouts API to pay the freelancer (including polling for PayPal's final status), Payments API for refunds, and idempotency keys so nothing is charged, paid or refunded twice.
  • Gemini: writes the hidden tests from the specification without ever seeing the submission, writes a reference solution, and does an independent review for prompt-injection attempts. If a model is busy, slow or out of quota, the app switches to another Gemini model automatically.
  • The AI never decides the payout alone. The payout depends on executed test results plus the manipulation check. If verification cannot complete, the escrow simply stays held.
  • Safe execution: the submission runs in a restricted subprocess (empty environment, temp directory, time and memory limits, network blocked). It receives only the test inputs, so it can never see or forge the expected answers.
  • Stack: Python, Streamlit, the google-genai SDK and PayPal's REST APIs. It's deployed on Streamlit Community Cloud and open source under the MIT license.
  • AI assistance: I used AI assistants (Gemini and Claude) as coding collaborators. I set up and tested the PayPal sandbox accounts, ran and debugged the full payment flows, and deployed the app.

Challenges I ran into

  • The AI's arithmetic was wrong. In one test run, Gemini's expected value was off by 20, so correct code was rejected. The fix: the app now executes an AI-written reference solution and keeps only tests where the AI's expected value matches the real output.
  • A payout that said "released" but wasn't. PayPal Payouts are asynchronous: they start as PENDING, and mine was later DENIED (I had accidentally paid the platform account to itself). The app now waits for PayPal's real verdict, puts the money back to "held" if it is denied, and blocks that mistake before any money moves.
  • Sandbox country limits. Accounts created in my country could not pay in USD or use Payouts, so the whole flow runs on US sandbox accounts.
  • Free-tier AI limits. Gemini was sometimes overloaded or out of daily quota, which led to the automatic model fallback and an option to use your own key.

Accomplishments that I'm proud of

A complete money loop (fund, verify, pay out or refund) that behaves safely when things go wrong. Every failure I hit became a safeguard, and the app stays "fail closed" when it cannot verify.

What I learned

Don't trust an AI's judgment or its arithmetic. Make it prove things with executed code. Treat async payment states honestly, and design so that failure means the money stays held.

What's next

Support more deliverable types (other languages, data, design), run submissions in containers (Docker/gVisor), add milestone splitting and dispute handling, and move to PayPal's marketplace tooling for real escrow compliance.

Built With

  • ai
  • github
  • google-gemini
  • paypal-orders-api
  • paypal-payments-api
  • paypal-payouts-api
  • paypal-sandbox
  • python
  • rest-apis
  • streamlit
  • streamlit-community-cloud
Share this project:

Updates

Submission history