Course contentsShow
← Security
Lesson 1942 of 3,05239. Cloud Security - Compute and ServerlessFree lesson

Function Execution Context and Isolation

How serverless platforms isolate function executions, container reuse, and the security implications of warm vs cold starts.

Function Execution Context and Isolation

You'll learn how serverless platforms protect your functions from each other—and what security gaps remain between cold and warm starts.

The Core Idea

When a serverless function executes, the cloud provider creates an isolated environment (typically a lightweight container or micro-VM) to run your code. This execution context includes memory, temporary storage, environment variables, and sometimes network sockets. Platforms attempt to isolate each function invocation, but for performance reasons, they often reuse these contexts across multiple invocations—creating security trade-offs.

Cold vs Warm Starts

  • Cold start: The platform provisions a fresh execution environment. Isolation is strongest here; no leftover data from previous runs.
  • Warm start: The platform reuses an existing execution context. Faster, but any in-memory data, open connections, or /tmp files from the previous invocation may still exist.

Think of it like hotel rooms: a cold start is a freshly cleaned room; a warm start is the same room you stayed in yesterday—faster check-in, but someone might have left something behind.

Security Implications

Container reuse means:

  • Secrets loaded into memory during one invocation might persist for the next
  • Temporary files in /tmp aren't guaranteed to be wiped
  • Global variables remain initialized
  • An attacker who compromises one invocation might poison the environment for subsequent calls

Platforms isolate between different functions strongly (separate containers), but isolation within successive invocations of the same function is weaker during warm starts.

Why It Matters

You cannot rely on a clean slate every invocation. Sensitive data must be explicitly cleared, and you should never trust leftover state. Conversely, attackers targeting serverless functions look for ways to exploit persistent state or shared execution contexts.

Key Takeaway:
Serverless platforms strongly isolate different functions but reuse execution contexts for performance, creating a security gap where warm starts may retain sensitive data, open connections, or attacker-planted state from previous invocations.