Portal Community

Threat Model

ThreatMitigation
Malicious code injected into AI Function by an attacker with DB accessSandbox blocks all I/O, network, and filesystem access; execution limits prevent DoS
Admin user creates a function that leaks data via return valueReview-required workflow for production functions; output logging and monitoring
Infinite loop / CPU exhaustionStatement count limit + execution timeout kill the function
Memory exhaustionHeap limit per sandbox instance; garbage collected after execution
Cross-tenant data accessSandbox receives only explicitly injected context (tenantId, agentId, userId)

Write Access Controls

Creating or modifying AI Functions requires the OctopusFunctionAuthor role. Activating a function for production requires an additional approval step:

// Role requirements:
// Create/update AI Function code:       OctopusFunctionAuthor
// Approve function for production use:  OctopusFunctionApprover
// View function list:                   OctopusAdmin (or above)

// A function starts as IsActive = false (cannot be called)
// An approver reviews the code and sets IsActive = true
POST /api/octopus/ai-functions/{functionId}/approve
Authorization: Bearer {approverToken}
{
  "approved": true,
  "notes":    "Reviewed — pure calculation, no I/O. Safe to activate."
}

Code Review Checklist

CheckWhat to Look For
No eval() callsDynamic code execution could bypass sandbox restrictions
No attempt to access __proto__ or Object.prototypePrototype pollution attacks
Return value does not contain sensitive dataPasswords, tokens, SSNs must not appear in return value
Input validation presentMissing validation can cause unexpected behaviour with LLM-generated inputs
No infinite loopswhile(true), recursion without base case
Bounded array/string operationsOperations on unbounded input can cause timeout

Audit Logging

// All AI Function executions are logged:
{
  "event":        "AIFunctionExecuted",
  "functionId":   "fn_7f3a...",
  "functionName": "calculate_leave_days",
  "agentId":      "agent_hr_01",
  "userId":       "user_mary_k",
  "tenantId":     "tenant_acme",
  "executedAt":   "2025-03-14T09:22:31Z",
  "durationMs":   12,
  "success":      true,
  "errorMessage": null
}

// Failed executions include error details:
{
  "event":        "AIFunctionExecuted",
  "functionName": "calculate_leave_days",
  "success":      false,
  "errorMessage": "Script execution timed out after 5000ms"
}
Restrict Who Can Create AI Functions

The OctopusFunctionAuthor role is effectively a code execution privilege. Grant it only to trusted developers and power users. In production environments, always require a separate approver (OctopusFunctionApprover) who was not involved in writing the function to review and activate it.