
AI & User Generated Backends with Rivet
Rivet now supports programmatically deploying AI-generated and user-generated actor code to sandboxed namespaces, enabling use cases like AI code execution, user sandbox environments, preview deployments, and multi-tenant applications.
The Problem With AI-Generated Backend Code
When AI agents generate backend code, they typically need to coordinate across multiple disconnected systems:
- Database schemas: Define tables, columns, and relationships
- API logic: Write endpoints that query and mutate data
- Schema synchronization: Keep database and API in sync as requirements change
Each system requires separate context, increasing token usage and cognitive load for the AI. More importantly, state and behavior can drift apart when defined separately, leading to bugs and inconsistencies.
How We Solved This
Rivet Actors: AI-Friendly Code Generation With Less Context & Fragmentation
Rivet Actors solve this by unifying state and logic in a single actor definition. Instead of coordinating between databases and APIs, state and behavior live together:
This consolidation eliminates fragmentation:
- Single source of truth: No need to keep migrations, schemas, and APIs in sync
- Less LLM context required: Generate one file instead of coordinating multiple systems
- Fewer errors: State and behavior can't drift apart when they're defined together
- More powerful generation: AI agents can focus on business logic instead of infrastructure plumbing
Rivet Namespaces: Fully Sandboxed Environments
Sandboxed namespaces provide isolated environments where each AI-generated or user-generated deployment runs independently with its own resources, tokens, and configuration. This enables safe multi-tenant deployments and user-generated code execution.
Use Cases
Sandboxed namespaces enable a variety of isolated deployment scenarios:
- AI-generated code: Deploy LLM-generated backends safely in isolated environments
- User sandbox environments: Give users their own sandboxed Rivet namespace to experiment
- Preview deployments: Create ephemeral environments for testing pull requests
- Multi-tenant applications: Isolate each customer in their own sandboxed namespace
How It Works
The deployment process involves four key steps:
-
Create sandboxed namespace: Programmatically create an isolated Rivet namespace using the Cloud API or self-hosted Rivet API
-
Generate tokens: Create the necessary authentication tokens:
- Runner token: Authenticates the serverless runner to execute actors
- Publishable token: Used by frontend clients to connect to actors
- Access token: Provides API access for configuring the namespace
-
Deploy code: Deploy the actor code and frontend programmatically to your serverless platform of choice (Vercel, Netlify, AWS Lambda, Freestyle, etc.)
-
Connect Rivet: Configure Rivet to run actors on your deployment in your sandboxed namespace
Show Me The Code
Here's a simplified example of the deployment flow using Freestyle (built specifically for this use case):
Call this deployment function whenever your AI agent generates new actor code or a user requests their own sandbox environment. The entire process takes seconds and creates a fully isolated, production-ready deployment.
Getting Started
To try deploying AI-generated or user-generated Rivet Actors:
- Check out the complete example on GitHub
- Read the full documentation guide
- Sign up for Rivet Cloud or self-host Rivet