AI and User-Generated Rivet Actors
This guide shows you how to programmatically create sandboxed Rivet environments and deploy custom actor code to them.
Use Cases
Deploying AI and user-generated Rivet Actors to sandboxed namespaces is useful for:
- AI-generated code deployments: Deploy code generated by LLMs in sandboxed 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
Rivet Actors For AI-Generated Backends
Traditional architectures require AI agents to coordinate across multiple disconnected systems: a database schemas, API logic, and synchronizing schemas & APIs.
With Rivet Actors, state and logic live together in a single actor definition. This consolidation means:
- Less LLM context required: No need to understand multiple systems or keep them in sync
- 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
How It Works
The deployment process involves four key steps:
- Create sandboxed Rivet namespace: Programmatically create a sandboxed Rivet namespace using the Cloud API or self-hosted Rivet API
- Generate tokens: Create the necessary tokens for authentication:
- 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 AI or user-generated code: Deploy the actor code and frontend programmatically to your serverless platform of choice (such as Vercel, Netlify, AWS Lambda, or any other provider). We'll be using Freestyle for this example since it's built for this use case.
- Connect Rivet to your deployed code: Configure Rivet to run actors on your deployment in your sandboxed namespace
Setup
Prerequisites
Before you begin, ensure you have:
- Node.js 18+ installed
- A Freestyle account and API token
- A Rivet Cloud account
Create Cloud API Token
- Visit your project on Rivet Cloud
- Click on "Tokens" in the sidebar
- Under "Cloud API Tokens" click "Create Token"
- Copy the token for use in your deployment script
Install Dependencies
Install the required dependencies:
Write Deployment Code
Write deployment code that handles namespace creation, token generation, Freestyle deployment, and runner configuration. This can be called from your backend to deploy actor and frontend code to an isolated Rivet namespace.
See the example repository for the complete project structure including the template directory and build process.
For more information on Freestyle deployment, see the Freestyle documentation.