Application Backend & Hosting
Applications generated by the Agent can not only write code, but also directly obtain a complete backend infrastructure and be deployed online with one click.
Backend Resource Overview
| Resource Type | Capability |
|---|---|
| PostgreSQL Database | Relational database (built on PostgREST), with full SQL support, foreign keys, transactions, etc. — ideal for structured data |
| Cloud Database | Document database (MongoDB-compatible) + MySQL. The Agent can automatically create collections/tables and write data |
| Cloud Functions | Deploy backend business logic (API endpoints), with support for HTTP triggers, scheduled triggers, and WebSocket |
| Cloud Storage (COS) | Store static assets and user-uploaded files, with access control support |
| Authentication | Provide sign-up and sign-in capabilities, including anonymous login, email/password, WeChat login, and more |
Hosting Options at a Glance
| Hosting Type | Description | Applicable Scenarios |
|---|---|---|
| Static Web Hosting | Deploy frontend web applications (HTML/CSS/JS) with CDN acceleration configured automatically | SPA applications, landing pages, documentation sites |
| Container Hosting | Deploy long-running backend services in containers, with auto scaling support | Backend services that need long connections or custom runtimes |
| HTTP Access Service | Unified gateway entry with wildcard routing, custom domains, and SSL certificates | Any scenario that needs to expose HTTP access externally |
Why Backend Capabilities Matter
For a Vibe Coding platform, "writing code" is only the first step. What users actually expect is to "generate a usable application with one sentence"—which means the app needs not only frontend pages, but also:
- Data persistence: Where is user data stored? → Cloud Database
- Backend logic: Where do the APIs run? → Cloud Functions
- File storage: Where are uploaded images stored? → Cloud Storage
- User system: How do users sign up and sign in? → Authentication
CloudBase lets the Agent complete all of these tasks through management APIs in a single workflow, without requiring end users to provision infrastructure themselves.
Typical Deployment Flow
After the Agent finishes coding, deployment can be completed with one-click management API calls:
- Frontend deployment:
hosting.deploy("./dist")→ static assets are uploaded to CDN and become effective immediately - Backend deployment:
function.deploy("apiHandler")→ Cloud Functions are deployed and HTTP routes are configured automatically - Access URL: a default address such as
https://xxx.app.tcloudbase.comis assigned automatically, with support for binding a custom domain
Integration Guide
Taking a Vibe Coding platform (similar to Lovable, Vercel v0) as an example, the typical flow for integrating CloudBase app backend is:
Step 1: Create a CloudBase Environment for Each User Project
CloudBase uses environments as its management unit. One environment = a full set of backend resources (database, cloud functions, cloud storage, static hosting, HTTP access service, etc.). The recommended model is one tenant, one environment, created automatically via the @cloudbase/manager-node SDK:
import CloudBase from '@cloudbase/manager-node'
// Initialize with platform master account credentials (no envId — will manage multiple envs)
const app = new CloudBase({
secretId: process.env.TENCENTCLOUD_SECRETID,
secretKey: process.env.TENCENTCLOUD_SECRETKEY,
})
const { env, commonService } = app
async function createUserEnv(projectId) {
// 1. Create the environment
const result = await commonService.call({
Action: 'CreateEnv',
Param: {
Alias: `project-${projectId}`,
PackageId: 'baas_personal',
Resources: ['flexdb', 'storage', 'function'],
Tags: [{ Key: 'projectId', Value: projectId }],
}
})
const envId = result.EnvId
// 2. Poll until the environment is ready
await waitForEnvReady(envId)
return envId
}
For detailed environment creation, billing, and lifecycle management, see Platform Integration Guide.
Step 2: Connect CloudBase in Your Coding Agent
Once the environment is created, the Coding Agent needs to operate resources within it (create tables, deploy functions, upload files, etc.). CloudBase provides multiple integration methods:
| Method | Description | Use Case | Documentation |
|---|---|---|---|
| CloudBase MCP | Operate CloudBase resources directly via MCP protocol. Agents can connect through stdio or HTTP | Agents with a built-in MCP Client (recommended) | Connect CloudBase MCP |
| Management SDK (Node.js) | Call management APIs through the @cloudbase/manager-node SDK | Node.js-based Agent services | SDK documentation |
| Management REST API | Call management APIs over HTTP, language-agnostic | Non-Node.js tech stacks | API documentation |
Step 3: Deploy the Application and Configure Access
Once the environment is ready, deploy cloud functions, static hosting, and configure the domain via SDK:
// Switch to the user's environment
const userApp = new CloudBase({
secretId: process.env.TENCENTCLOUD_SECRETID,
secretKey: process.env.TENCENTCLOUD_SECRETKEY,
envId: userEnvId,
})
const { functions, hosting } = userApp
// 1. Deploy a cloud function
await functions.createFunction({
name: 'todoApi',
type: 'HTTP',
code: {
zipFile: base64Code, // Base64-encoded ZIP package
},
})
// 2. Deploy frontend to static hosting
await hosting.uploadFiles({
localPath: './dist',
cloudPath: '/',
})
// 3. Configure HTTP Access Service route (via commonService)
await userApp.commonService.call({
Action: 'CreateHTTPServiceRoute',
Param: {
EnvId: userEnvId,
Domain: {
Domain: `${projectId}.your-platform.com`,
Protocol: 'HTTP_AND_HTTPS',
CertId: certId,
Enable: true,
Routes: [{
Path: '/api',
UpstreamResourceType: 'CBR',
UpstreamResourceName: 'todoApi',
Enable: true,
}]
}
}
})
For complete domain binding, DNS configuration, and security domain setup, see Platform Integration Guide - Domain & Security Domain.
Integrating CloudBase in a Coding Agent
Example: Operating CloudBase via MCP in OpenCode
The following demonstrates how to configure CloudBase MCP in OpenCode (an open-source terminal AI Coding tool), allowing the Agent to directly operate cloud databases, deploy functions, and more:
1. Configure the MCP Server
Create .opencode.json in the project root:
{
"mcpServers": {
"cloudbase": {
"command": "npx",
"args": ["-y", "@cloudbase/cloudbase-mcp@latest"],
"env": {
"CLOUDBASE_ENV_ID": "your-env-id",
"TENCENTCLOUD_SECRETID": "your-secret-id",
"TENCENTCLOUD_SECRETKEY": "your-secret-key"
}
}
}
}
Note: In a real Vibe Coding platform scenario, the secrets here should be user environment-level secrets (not platform-level secrets), ensuring each user can only operate their own CloudBase environment. See Tenant Isolation for details.
2. Operate cloud resources directly in conversation
Once configured, the OpenCode Agent can operate CloudBase through natural language:
> Create a todos table with title, completed, and created_at fields
Agent calls MCP: cloudbase.db.createCollection({ name: "todos", schema: ... })
✅ Collection todos created
> Write a cloud function that provides addTodo and listTodos APIs
Agent calls MCP: cloudbase.function.deploy({ name: "todoApi", code: "..." })
✅ Cloud function todoApi deployed, URL: https://your-env-id.api.tcloudbasegateway.com/todoApi
> Deploy the frontend build output
Agent calls MCP: cloudbase.hosting.deploy({ path: "./dist" })
✅ Static hosting deployed: https://your-env-id.app.tcloudbase.com
The same MCP configuration works with Cursor, Cline, Claude Code, and other AI Coding tools that support the MCP protocol. See the CloudBase MCP Configuration Guide for details.
Example 2: Operating CloudBase via MCP in a CloudBase Sandbox
This scenario is designed for online Vibe Coding platforms — the Agent runs in a Cloud Function, manages the Sandbox through the Sandbox SDK, starts a CloudBase MCP Server inside the Sandbox, and then operates the user's CloudBase environment through an MCP Client.
// 1. Issue user env-level temporary credentials
const credentials = await generateEnvCredentials(userEnvId);
// 2. Start the Sandbox with user-level secrets injected
const sandbox = new AgentSandbox({
envId: userEnvId,
secretId: agentConfig.secretId, // Platform credentials, used only for Sandbox SDK RPC auth
secretKey: agentConfig.secretKey,
envVars: {
CLOUDBASE_ENV_ID: userEnvId,
TENCENTCLOUD_SECRETID: credentials.secretId,
TENCENTCLOUD_SECRETKEY: credentials.secretKey,
}
});
// 3. Start CloudBase MCP Server inside the Sandbox
await sandbox.commands.run('npx @cloudbase/cloudbase-mcp@latest');
// 4. Agent Loop connects to the MCP Server via MCP Client
const mcpClient = sandbox.connectMCP({ transport: 'stdio' });
// 5. Now you can operate the user's CloudBase environment via MCP
// Create a database collection
await mcpClient.call('cloudbase.db.createCollection', { name: 'todos' });
// Deploy a cloud function
await mcpClient.call('cloudbase.function.deploy', {
name: 'todoApi',
code: await sandbox.files.read('/app/functions/todoApi/index.js')
});
// Deploy frontend to static hosting
await sandbox.commands.run('npm run build');
await mcpClient.call('cloudbase.hosting.deploy', { path: '/app/dist' });
// 6. Save workspace snapshot when done
await sandbox.snapshot(sessionId);
For the complete architecture and security design of Sandbox SDK and MCP Client, see Agent Runtime.