Skip to main content
Sinas has a dual-execution model for functions, plus dedicated queue workers for async job processing.

Sandbox Containers

The sandbox container pool is a set of pre-warmed, generic Docker containers for executing untrusted user code. This is the default execution mode for all functions (shared_pool=false). How it works:
  • On startup, the pool creates sandbox_min_size containers (default: 4) ready to accept work.
  • When a function executes, a container is acquired from the idle pool, used, and returned.
  • Containers are recycled (destroyed and replaced) after sandbox_max_executions uses (default: 100) to prevent state leakage between executions.
  • If a container errors during execution, it’s marked as tainted and destroyed immediately.
  • A background replenishment loop monitors the idle count and creates new containers whenever it drops below sandbox_min_idle (default: 2), up to sandbox_max_size (default: 20).
  • Health checks run every 60 seconds to detect and replace dead containers.
Isolation guarantees: Each container runs with strict resource limits and security hardening: Runtime scaling: The pool can be scaled up or down at runtime without restarting the application:
Package installation: When new packages are approved, existing containers don’t have them yet. Use the reload endpoint to install approved packages into all idle containers:
Containers that are currently executing are unaffected. New containers created by the replenishment loop automatically include all approved packages.

Shared Containers

Functions marked shared_pool=true run in persistent shared containers instead of sandbox containers. This is an admin-only option for trusted code that benefits from longer-lived containers. Differences from sandbox: When to use shared_pool=true (shared containers):
  • Functions created and maintained by admins (not user-submitted code)
  • Functions that import heavy libraries (pandas, scikit-learn) where container startup cost matters
  • Performance-critical functions that benefit from warm containers
Management:

Queue Workers

All function and agent executions are processed asynchronously through Redis-based queues (arq). Two separate worker types handle different workloads: Function workers dequeue function execution jobs, route them to either sandbox or shared containers, track results in Redis, and handle retries. Failed jobs that exhaust retries are moved to a dead letter queue (DLQ) for inspection and manual retry. Agent workers handle chat message processing — they call the LLM, execute tool calls, and stream responses back via Redis Streams. Agent jobs don’t retry because LLM calls with tool execution have side effects. Scaling is controlled via Docker Compose replicas:
Each worker sends a heartbeat to Redis every 10 seconds (TTL: 30 seconds). If a worker dies, its heartbeat key auto-expires, making it easy to detect dead workers. Job status tracking:
Jobs go through states: queuedrunningcompleted or failed. Stale or orphaned jobs can be cancelled via the admin API:
Cancellation updates the Redis status to cancelled and marks the DB execution record as CANCELLED. It also publishes to the done channel so any waiters unblock. This is a soft cancel — it does not kill running containers. Results are stored in Redis with a 24-hour TTL.

System Endpoints

Admin endpoints for monitoring and managing the Sinas deployment. All require sinas.system.read:all or sinas.system.update:all permissions. Health check:
Returns a comprehensive health report:
  • services — All Docker Compose containers with status, health, uptime, CPU %, and memory usage. Infrastructure containers (redis, postgres, pgbouncer) are listed first, followed by application containers sorted alphabetically. Sandbox and shared worker containers are included.
  • host — Host-level CPU, memory, and disk usage (read from /proc on Linux).
  • warnings — Auto-generated alerts at three levels:
    • critical — No queue workers running, or infrastructure services (redis, postgres, pgbouncer) down
    • warning — Non-infrastructure services down, unhealthy containers, DLQ items, queue backlog >50, disk/memory >90%
    • info — Disk/memory >75%
Container restart:
Restarts any Docker container by name (15-second timeout). Returns 404 if the container doesn’t exist. Flush stuck jobs:
Cancels all jobs that have been stuck in running state for over 2 hours. Useful for recovering from worker crashes or orphaned jobs.

Dependencies (Python Packages)

Functions can only use Python packages that have been approved by an admin. This prevents untrusted code from installing arbitrary dependencies. Approval flow:
  1. Admin approves a dependency (optionally pinning a version)
  2. Package becomes available in newly created containers and workers
  3. Use POST /containers/reload or POST /workers/reload to install into existing containers
Optionally restrict which packages can be approved with a whitelist:

Configuration Reference

Container pool: Function execution: Workers and queues: Packages: