Skip to content

Extension SDK

Sandboxing

What extensions can and cannot do at runtime. The security boundaries that keep one tenant’s code from affecting another’s scheduling.

Key points

  • Extensions run in VM2-isolated contexts — no filesystem, no raw network, no child processes
  • External services are injected by the runtime based on manifest declarations
  • CPU and memory are bounded per execution; runaway extensions get killed
  • Code is signed at deploy and verified on load; tampered code refuses to execute

The runtime model

Extensions are user code running inside a multi-tenant engine. That introduces real risk — a poorly-written or malicious extension could exhaust resources, leak data across tenants, or block scheduling decisions for everyone. The runtime is built to prevent each of these.

Three layers of isolation apply to every extension execution:

  • Module sandbox — extensions run in VM2 with a locked-down module loader. Only allowlisted modules can be imported; everything else throws at load time.
  • Resource bounds — CPU time, wall clock time, and memory are all limited per execution. Slow or runaway extensions get terminated cleanly.
  • Service injection — anything that needs to talk to the outside world (HTTP clients, database access) comes through the runtime as injected services. No raw network or storage access.

What’s allowed

Inside an extension, you can:

  • Use the SDK’s typed interfaces and helpers
  • Import allowlisted utility libraries (lodash, date-fns, zod, decimal.js, and similar pure-JS modules)
  • Call services that your manifest declares (Google Maps, custom CRMs, payment processors — whatever the customer has connected)
  • Read entity and event data through the runtime context (ctx.events.findByEntity(), etc.)
  • Use the runtime cache (ctx.cache.get/set) for keying calculations and reducing external calls
  • Emit observability events through ctx.logger, ctx.trace, and ctx.metrics
example importstypescript
// Allowed
import { z } from 'zod';                    // ✓ schema validation
import _ from 'lodash';                     // ✓ utility functions
import { format } from 'date-fns';          // ✓ date helpers
import { Decimal } from 'decimal.js';       // ✓ precise arithmetic

// Blocked at load time — extension will refuse to load
import fs from 'node:fs';                   // ✗ filesystem access
import { execSync } from 'node:child_process'; // ✗ process spawning
import http from 'node:http';               // ✗ raw network
import { Worker } from 'node:worker_threads'; // ✗ worker threads

What’s blocked

The following are unconditionally blocked. Attempting any of them will fail — either at load time (refused module) or at runtime (thrown error):

  • Filesystem access — node:fs and friends. Use the runtime cache or replicated entity data instead.
  • Child process spawning — node:child_process, node:worker_threads. Extensions are single-threaded by design.
  • Raw network calls — fetch, node:http, node:https. All HTTP must go through injected service clients.
  • Process introspection — process.env is empty; process.exit() is a no-op. Configuration comes through ctx.config.
  • Eval and Function constructor — dynamic code execution is blocked. Stay within static TypeScript.
  • Native modules — anything with a .node binary won’t load. Pure-JS libraries only.

The allowlist is conservative

Modules get added to the allowlist on demand based on customer needs. If you require a module not currently allowed, file a request through your account contact. Common pure-JS utilities with no native dependencies are usually approved within a release cycle.

Service injection

Anything that talks to the outside world is injected by the runtime. Your manifest declares which services your extension needs; the runtime hydrates them with the customer’s configured credentials at execution time:

flexi.config.jsonjson
{
  "extensions": [
    {
      "id": "travel_time_calculator",
      "type": "calculation_function",
      "entry": "src/calculators/TravelTimeCalculator.ts",
      "version": "1.2.0",
      "services": ["googleMaps"]
    }
  ]
}

At runtime, the declared services appear on the context object, typed and ready to use:

// In your extension, the runtime injects the service onto ctx
async calculate(ctx, params) {
  // ctx.googleMaps is typed and ready to use
  const route = await ctx.googleMaps.directions({ ... });

  // ctx.fetch is NOT available — use injected services
  // const r = await fetch('https://...'); // will throw at runtime
}

You never see raw credentials. The customer’s API keys live in the runtime’s secret store; injected clients use them transparently. This is also how customer-isolation works — organization A’s extensions get organization A’s credentials, never anyone else’s.

Resource limits

Every extension execution is bounded:

  • Wall clock timeout — type-specific. Calculators 5s, validators 10s, allocators 30s. Configurable per-extension in the manifest, but capped at engine-wide maximums.
  • Memory ceiling — 256MB heap per execution. Allocations beyond this trigger an OOM that’s caught and surfaced as a structured failure.
  • Service call rate — extensions can make at most 50 outbound service calls per execution. Above that, the runtime returns a synthetic rate-limit error to discourage unbounded loops.
  • Cache size — extensions can store up to 10MB per cache key, with total cache budget of 100MB per extension version.

When a limit is hit, the extension’s execution returns a structured failure that the engine treats as a soft fail. The constraint chain continues (or, for allocators, the affected candidate is dropped from ranking). Limits never crash the engine.

Code signing

Every deployed extension is signed. Signing prevents tampering between deploy and execution and ensures the runtime only executes code that traces back to your organization’s signing key.

# 1. Build your extensions locally
flexischeduler-cli build

# 2. Sign with your organization's signing key
flexischeduler-cli sign --key ./keys/extension-signing.pem

# 3. Push to FlexiScheduler
flexischeduler-cli deploy --target production

# Output:
# ✓ TravelTimeCalculator@1.2.0 — signed (sha256: a8f4c2...)
# ✓ CarePlanValidator@1.0.0    — signed (sha256: 19fe4d...)
# ✓ Pushed to organization org_a91e
# ✓ Active in template home_care_v1

Signing keys are managed in the Config Studio. They’re organization-scoped, rotatable, and never leave your control — the FlexiScheduler runtime stores only the public verification key.

The deploy step records each extension’s SHA-256 hash in the audit log. On every execution, the runtime re-verifies the hash against the signature. Tampered code refuses to execute and the failure is surfaced to your security team via the standard alert pipeline.

Signing key management

For most teams, signing keys live in your CI’s secret store (Vault, AWS Secrets Manager, GitHub Actions secrets) and are rotated quarterly. The flexischeduler-cli expects a PEM-encoded private key; rotation is a single command and old signatures remain valid until you explicitly revoke.