Skip to content
TailoredAI
All work

Case study

Infrastructure for an AI app-building platform

Sandboxed execution for agent-generated code, LLM cost control and tracing, and production on-call, in a long-running engagement.

Client
A platform where users' AI agents build and run web apps, on GCP
Stack
Python, FastAPI, Daytona, Docker, LiteLLM, Redis, PostgreSQL, OpenTelemetry, Terraform, GCP

The problem

The platform's AI agents write and run code for its users. That code needed isolated machines for live previews, publishing and agent commands, on a third-party sandbox provider, without one user's agent affecting another's and without leaking machines or spend. At the same time, LLM spend and latency per model and per agent were hard to see, and the production infrastructure needed someone on call.

SANDBOXED EXECUTIONAgents and previewsper projectCommand queueone command at a timeSandbox interfaceleases · sync · replaceDaytonaproductionDockerlocal and testsReaperremoves abandoned machinesLLM CALLSAgentsand chatLLM gatewayrouting · fallbacksModel providersplatform or own keysCost meteringbudgets in RedisTracingOpenTelemetry spans
How agent-generated code reaches an isolated machine, and how every LLM call is routed, metered and traced.

What we did

Sandboxed execution

  • One sandbox interface over Daytona and Docker, with leases, idempotent acquire and replace, a reaper for abandoned machines and signed-URL file sync.
  • A per-project command queue run by a leader-elected actor, with durable records of unsaved outputs and a reconciler that releases abandoned work.
  • A conformance suite across every runtime, a nightly run against the live provider, and soak and fault-injection tests.
  • Capacity sized to the provider's limit of about 250 running sandboxes.
  • A publishing pipeline with an ephemeral build machine per deploy that fails on non-zero exits and timeouts.

LLM cost control and tracing

  • Token cost metering through LiteLLM, with cached provider pricing.
  • Usage budgets in Redis that are restored when an LLM call fails.
  • Bring-your-own-key billing alongside platform-funded agents.
  • Model routing and fallbacks, per-model context limits and conversation compaction.
  • Per-call OpenTelemetry spans for model, tokens, cost and latency in Cloud Trace, with a dashboard.

Reliability and on-call

  • Traced a production secret that kept disappearing to staging deploys rewriting a Terraform list shared with production, fixed it the same night, and wrote up the pipeline changes that keep staging away from production resources.
  • Patched three parser denial-of-service advisories.
  • Terraform for secrets, Pub/Sub and storage lifecycles, and GitHub Actions CI.

Outcomes

  • Previews, publishing and agent commands running on isolated machines, from interface to the new module in about four weeks.
  • Cost and latency visible per model and per agent, with budget accounting that stays correct when calls fail.
  • A production incident traced and fixed the same night, with pipeline changes to prevent a repeat.