Edge Functions
Write server-side JavaScript or Python functions and invoke them via API, webhooks, or cron triggers. Full database access via the built-in zMesh SDK, automatic version history, and sandboxed execution.
Custom-Built Serverless Runtime
zMesh Edge Functions are built from scratch — no AWS Lambda, no Cloudflare Workers, no third-party FaaS. Each function runs in an isolated subprocess with OS-level resource limits (CPU, memory, file size, process count), ephemeral workspaces, and automatic cleanup. The runtime injects a pre-authenticated zMesh SDKwith direct database access to your project's PostgreSQL instance.
Architecture
Subprocess Isolation
Each invocation runs in its own process with RLIMIT_AS, RLIMIT_CPU, RLIMIT_NPROC, RLIMIT_FSIZE enforced at the OS level.
Direct DB Access
The zmesh.db SDK connects directly to your project's PostgreSQL via an auto-injected DSN. No API layer overhead.
Secret Stripping
Platform secrets (JWT_SECRET_KEY, DATABASE_URL, etc.) are stripped from the subprocess environment before execution.
Ephemeral Workspace
Each run uses a TemporaryDirectory with HOME and TMPDIR redirected. Cleaned up automatically after execution.
Concurrency Control
Dual-layer semaphores — global platform limit + per-project limit — prevent resource exhaustion.
Auto Version History
Every code update snapshots the previous version. Rollback to any version instantly.
Execution Flow
new Function(), Python: exec())Create a Function
{
"name": "send-welcome",
"language": "javascript",
"entry_point": "handler",
"code": "exports.handler = async (payload, zmesh) => { ... }",
"timeout_ms": 5000,
"env_vars": {
"GREETING": "Hello"
}
}Supported Languages
| Language | Runtime | DB Driver | SDK Injection |
|---|---|---|---|
| JavaScript | Node.js | pg (auto-included) | new Function() wrapper |
| Python | Python 3.11 | psycopg2 (auto-included) | exec() with SDK class |
zMesh SDK (In-Function)
Every function receives a zmesh object with built-in database access and env vars:
| Method | Description |
|---|---|
| zmesh.db.query(sql, params) | Execute raw SQL, returns rows |
| zmesh.db.queryOne(sql, params) | Execute SQL, return single row |
| zmesh.db.insert(table, data) | Insert row, returns inserted data |
| zmesh.db.select(table, where, params) | Select rows with conditions |
| zmesh.db.update(table, data, where, params) | Update rows matching condition |
| zmesh.db.remove(table, where) | Delete rows matching condition |
| zmesh.env.KEY_NAME | Access environment variables |
| zmesh.projectId | Current project identifier |
exports.handler = async (payload, zmesh) => {
// Raw SQL query
const rows = await zmesh.db.query(
"SELECT * FROM users WHERE age > $1", [18]
);
// Single row fetch
const user = await zmesh.db.queryOne(
"SELECT * FROM users WHERE id = $1", [payload.id]
);
// Insert a record
const log = await zmesh.db.insert("logs", {
action: "signup",
user_id: payload.id,
});
// Update records
await zmesh.db.update(
"users",
{ name: "New Name" },
"id = $1",
[payload.id]
);
// Delete records
await zmesh.db.remove("sessions", "expired_at < NOW()");
// Access env vars
const greeting = zmesh.env.GREETING;
return { users: rows.length, greeting };
};def handler(payload, zmesh):
# Raw SQL query
rows = zmesh.db.query(
"SELECT * FROM users WHERE age > %s", (18,)
)
# Single row
user = zmesh.db.query_one(
"SELECT * FROM users WHERE id = %s",
(payload["id"],)
)
# Insert
zmesh.db.insert("logs", {
"action": "signup",
"user_id": payload["id"],
})
# Access env vars
greeting = zmesh.env.GREETING
return {"users": len(rows), "greeting": greeting}Invoke (Dashboard Auth)
// Request
{
"payload": { "user_id": "abc123" }
}
// Response
{
"status": "success",
"result": { "message": "Welcome Rahul" },
"duration_ms": 230
}Public Invoke (API Key Auth)
Invoke functions from your app using an API key and the function slug:
curl -X POST https://api.zmesh.in/api/functions/send-welcome \
-H "x-api-key: zb_your_api_key" \
-H "Content-Type: application/json" \
-d '{"user_id": "abc123"}'API Reference
| Method | Path | Description |
|---|---|---|
| GET | /functions | List all functions |
| POST | /functions | Create function |
| GET | /functions/{id} | Get function details + code |
| PATCH | /functions/{id} | Update function code/config |
| DELETE | /functions/{id} | Delete function |
| POST | /functions/{id}/invoke | Invoke function (dashboard auth) |
| POST | /api/functions/{slug} | Invoke function (API key auth) |
| GET | /functions/{id}/invocations | Invocation history & logs |
| GET | /functions/{id}/versions | Version history |
| POST | /functions/{id}/versions/{v}/rollback | Rollback to version |
Version History & Rollback
Automatic Snapshots
Every time you update a function's code via PATCH, the previous version is automatically saved to the function_versions table with timestamp and entry point.
Instant Rollback
Rollback saves the current state as a new version before overwriting with the historical snapshot. This means rolling back is always safe — you can rollback-the-rollback.
Sandbox Limits
| Resource | Limit | Enforcement |
|---|---|---|
| Timeout | Configurable per function (default 10s) | asyncio timeout |
| Memory | 256 MB (configurable) | RLIMIT_AS |
| CPU Time | timeout + 2 seconds | RLIMIT_CPU |
| File Output | 10 MB | RLIMIT_FSIZE |
| Processes | 50 max child processes | RLIMIT_NPROC |
| Concurrency | Global + per-project semaphores | Application-level |
| Network | Full outbound HTTP access | Unrestricted |
CLI Usage
# Deploy a function
zmesh functions deploy ./send-welcome.js
# List all functions
zmesh functions list
# Invoke a function
zmesh functions invoke send-welcome --data '{"user_id": "abc123"}'
# View invocation logs
zmesh functions logs send-welcome