Preparing your workspace...

assistant-chat.tsx2.5k
utils.ts850
button.tsx720
Quick Actions
codmir
Docs
Discord
Get started
API
  • Introduction
  • Installation
  • Your First Project
  • Your First Agent
  • Overview
  • CodmirClient
  • API Client
    • Next.js
    • React Native
    • Express
    • Browser
    • Remix
    • Serverless
  • Webhooks

Run AI workloads in the cloud with hybrid execution, sandboxes, and built-in governance.

Serverless SDK

The Serverless SDK lets you define functions that run locally during development and in the cloud in production. It provides a Modal-like API with hybrid execution backends, interactive sandboxes, persistent volumes, and built-in governance via Grace policies.

npm install @codmir/sdk
import { app, fn } from '@codmir/sdk/serverless';

Quick Start

import { app, fn } from '@codmir/sdk/serverless';

const myApp = app({ name: 'data-pipeline' });

const processData = fn(myApp, {
  cpu: 2,
  memory: '4GB',
  timeout: 300,
})(async (data: string) => {
  // Your code runs in the cloud
  return data.toUpperCase();
});

// Local development
const localResult = await processData.local('test data');

// Cloud execution
const remoteResult = await processData.remote('real data');

// Auto-select based on environment
const result = await processData.call('auto data');

Apps

An app is a container that groups functions, sandboxes, and configuration together.

import { CodmirApp, createApp } from '@codmir/sdk/serverless';

const app = new CodmirApp({
  name: 'my-app',
  image: 'python:3.11',
  secrets: ['OPENAI_API_KEY'],
  volumes: { '/data': 'my-volume' },
  grace: {
    enabled: true,
    preferGreen: true,
  },
});

App Config

OptionTypeDescription
namestringUnique app identifier
imagestringDefault container image for all functions
secretsstring[]Secrets injected into all functions
volumesRecord<string, string>Default volume mounts
graceGraceConfigGovernance configuration

Functions

Functions are the core execution unit. Define them with resource requirements and a handler.

const embed = app.function({
  cpu: 4,
  memory: '8GB',
  gpu: 'T4',
  timeout: 600,
  retries: 2,
  pool: 'auto',
})(async (texts: string[]) => {
  // Runs with 4 CPUs, 8GB RAM, and a T4 GPU
  return await generateEmbeddings(texts);
});

Local vs Remote Execution

// Always runs locally (for development/testing)
const result = await embed.local(['hello', 'world']);

// Always runs in the cloud
const result = await embed.remote(['hello', 'world']);

// Auto-selects based on NODE_ENV
const result = await embed.call(['hello', 'world']);

Function Config

OptionTypeDefaultDescription
cpunumber1CPU cores
memorynumber | string'256MB'RAM allocation
gpuboolean | stringfalseGPU type: 'T4', 'A10G', 'A100', 'H100'
timeoutnumber300Max execution time in seconds
retriesnumber0Retry count on failure
concurrencyLimitnumber—Max concurrent executions
poolExecutionPool'auto'Preferred execution backend
imagestringApp defaultContainer image
secretsstring[][]Secrets to inject
volumesRecord{}Volume mounts
envRecord{}Environment variables
checkpointsbooleanfalseEnable checkpointing for long tasks
schedulestring—Cron expression for scheduled runs

Sandboxes

Sandboxes are interactive cloud environments for running commands, reading/writing files, and iterating on code.

const sandbox = app.sandbox({ image: 'python:3.11' });
await sandbox.spawn();

// Execute commands
await sandbox.exec('pip install numpy pandas');
const result = await sandbox.exec('python script.py');
console.log(result.stdout);

// Read and write files
await sandbox.writeFile('/app/data.json', JSON.stringify(data));
const content = await sandbox.readFile('/app/output.json');

// Clean up
await sandbox.terminate();

Sandbox Config

OptionTypeDescription
imagestringBase container image (required)
cpunumberCPU cores
memorynumber | stringRAM allocation
gpuboolean | stringGPU type
timeoutnumberMax lifetime in seconds (default: 3600)
workdirstringWorking directory inside the container
envRecordEnvironment variables
secretsstring[]Secrets to inject
volumesRecordVolume mounts
webAccessbooleanEnable web access via tunnel

Custom Images

Build custom container images with pre-installed dependencies.

import { createImage } from '@codmir/sdk/serverless';

const mlImage = createImage({
  base: 'python:3.11-slim',
  pythonPackages: ['torch', 'transformers', 'numpy'],
  systemPackages: ['ffmpeg', 'libsndfile1'],
  runCommands: ['python -c "import torch; print(torch.__version__)"'],
  copyFiles: [{ from: './models', to: '/app/models' }],
  env: { TRANSFORMERS_CACHE: '/app/cache' },
  workdir: '/app',
});

Volumes

Persistent storage that survives across function executions.

import { createVolume } from '@codmir/sdk/serverless';

const dataVol = createVolume({
  name: 'training-data',
  size: 100, // GB
  region: 'us-east-1',
});

// Mount in a function
const train = fn(myApp, {
  gpu: 'A100',
  volumes: { '/data': 'training-data' },
})(async () => {
  // /data persists between runs
});

Secrets

Securely inject credentials into function environments.

import { createSecret } from '@codmir/sdk/serverless';

const apiKey = createSecret({
  name: 'OPENAI_API_KEY',
  envVar: 'OPENAI_API_KEY',
});

const generate = fn(myApp, {
  secrets: ['OPENAI_API_KEY'],
})(async (prompt: string) => {
  // process.env.OPENAI_API_KEY is available
});

Decorator API

The decorator-style API provides a Modal-like syntax for defining serverless resources.

import { app, fn, web_endpoint, cron, method } from '@codmir/sdk/serverless';

const myApp = app({ name: 'my-service' });

// Basic function
const process = fn(myApp, { cpu: 2 })(async (data: string) => {
  return data.toUpperCase();
});

// Web endpoint
const api = web_endpoint(myApp, { method: 'POST' })(async (req) => {
  return { status: 'ok', data: req.body };
});

// Scheduled function (cron)
const dailyReport = cron(myApp, '0 9 * * *')(async () => {
  await generateDailyReport();
});

Class Methods

class DataProcessor {
  @method(myApp, { cpu: 4, memory: '8GB' })
  async process(data: string) {
    return data.toUpperCase();
  }
}

Execution Layer

For programmatic control over execution, use the lower-level execution functions.

import { execute, executeAsync, executeLocal } from '@codmir/sdk/serverless';

Execution Results

Every execution returns an ExecutionResult with metrics and status.

interface ExecutionResult<T> {
  id: string;
  status: ExecutionStatus;
  result?: T;
  error?: string;
  metrics: {
    durationMs: number;
    queuedMs?: number;
    coldStartMs?: number;
    cpuUsage?: number;
    memoryUsageMb?: number;
    creditsUsed: number;
    carbonFootprint?: number;   // gCO2e
    pool: ExecutionPool;
  };
  logs?: string[];
  artifacts?: ExecutionArtifact[];
  checkpoint?: unknown;
}

Execution Pools

Functions can run on different backends depending on cost, latency, and availability needs.

PoolDescription
autoAutomatically selects the best pool (default)
modalModal.com infrastructure
fargateAWS Fargate containers
githubGitHub Actions runners
communityCommunity-contributed compute
localLocal machine

Streaming and Progress

import { logs, progress, checkpoint } from '@codmir/sdk/serverless';

Track long-running executions with progress callbacks, log streaming, and checkpointing for resumable tasks.

Grace Governance

Every app and function can be configured with Grace policies for ethical execution governance.

const app = new CodmirApp({
  name: 'sensitive-pipeline',
  grace: {
    enabled: true,
    requireApproval: true,
    maxBudget: 100,           // Max credits per execution
    preferGreen: true,        // Route to low-carbon compute
    impactCategory: 'medium',
  },
});
OptionTypeDefaultDescription
enabledbooleantrueEnable Grace policy enforcement
requireApprovalbooleanfalseRequire human approval before execution
maxBudgetnumber—Maximum credits per execution
preferGreenbooleanfalsePrefer low-carbon compute regions
impactCategorystring'safe'Ethical impact level: safe, low, medium, high

TypeScript Support

import type {
  AppConfig,
  FunctionConfig,
  SandboxConfig,
  ImageConfig,
  VolumeConfig,
  SecretConfig,
  ExecutionResult,
  ExecutionStatus,
  ExecutionPool,
  ResourceSpec,
  GraceConfig,
  CallOptions,
  StreamEvent,
  BatchConfig,
  BatchResult,
} from '@codmir/sdk/serverless';

Related

Agent SDK

Autonomous agents that can dispatch serverless workloads

AI Monitoring

Track costs and tokens for AI calls in serverless functions

Cluster

Multi-node orchestration for distributed workloads

Open in ChatGPTOpen in ClaudeConnect MCP on CursorConnect MCP on WindsurfEdit on GitHub
codmir
Products
Desktop AppMobile AppIDE ExtensionAI AgentsOverseerVoice ModeCortex ProtocolHive MindGame Dev (Godat)PricingDownload
Solutions
AI Code AgentsCode ReviewError TrackingSelf-HealingDeploy TrackingAI Tracking SDKWorkflow AutomationTesting FrameworkTime TrackingVoice Control
Platform
ProjectsTickets & BoardsAgent MarketplaceIntegrationsTemplatesApp HubAdmin PanelAnalytics
Integrations
GitHubSlackDiscordVercelSentryRailwayLinearAll Integrations
Developers
DocumentationAPI ReferenceSDKCLIDeveloper PortalMarketplaceMCP ConnectorsWebhooksExamplesnpm Packages
Resources
BlogChangelogCommunityTutorialsGet StartedSupportStatusFeedback
Company
AboutCareersContact SalesKickstarterReferral Program
Legal
Terms of UsePrivacy PolicyEULATrademarkSecurity
Download on the App StoreGet it on Google Play

Codmir™ 2026. All rights reserved.

Free & open source SDK — Apache 2.0 License