Skip to content

Per-actor environment variables #3876

Open

Description

Problem

Actor has no field for per-actor environment variables or configuration overrides.Container.env is defined only on ActorTemplate (api/ateapi/v1/ateapi.proto).

Workloads often share an ActorTemplate (same container image, resource limits, and volume layout) while needing distinct non-secret configuration per Actor, such as a session ID, tenant or project name, model name, or feature flags. Today, varying any environment variable across actors requires creating a separate ActorTemplate per actor, which duplicates template records and golden snapshot builds.

Constraint: SNAPSHOT_FIDELITY_MEMORY snapshots

As noted in docs/reference/api-guide.md (SystemInfo Volumes) and #1449:

  • When a container starts during golden snapshot initialization, its process environment (envp) is copied into the process address space and cached by the language runtime (os.Environ, process.env, os.environ).
  • When an actor restores from a SNAPSHOT_FIDELITY_MEMORY snapshot (the default for golden snapshots and source_tag clones), both ateworker-gvisor (runsc restore) and ateworker-microvm (restoreMemoryFidelity) resume the checkpointed process memory directly. No new container process is spawned, so changes to the OCI bundle's process.env have no effect on already-running processes.

By contrast, cold boots (GOLDEN_SNAPSHOT_MODE_DISABLED) and SNAPSHOT_FIDELITY_VOLUMES or SNAPSHOT_FIDELITY_ROOTFS restores start fresh container processes from the OCI spec built by atelet (prepareOCIBundles -> ocispec.Build).

Options to explore

Option 1: Per-actor env overrides for cold-boot and non-memory restores

Allow Actor to specify per-container EnvVar overrides that workloadSpecFromActorTemplate (cmd/ateapi/internal/controlapi/workload_spec.go) merges over ActorTemplate.containers[].env (with actor values taking precedence over template values, which take precedence over the image ENV in resolveActorEnv).

Open question on SNAPSHOT_FIDELITY_MEMORY interactions:

  • Reject actor-level env on CreateActor if the actor initializes from a SNAPSHOT_FIDELITY_MEMORY golden snapshot or source_tag?
  • Or automatically downgrade the initial restore of a golden snapshot / source_tag from SNAPSHOT_FIDELITY_MEMORY to SNAPSHOT_FIDELITY_ROOTFS when actor env overrides are set, preserving the warmed rootfs while starting fresh container processes with the actor's environment?

Option 2: Project per-actor key-value configuration via SystemInfoVolumeSource

SystemInfoVolumeSource files are regenerated on the host by atelet on every Run and Restore and excluded from checkpoints (#802). Extending Actor with a bounded key-value map (or building on annotations in #3617) and projecting those entries into the systemInfo volume (for example as individual files or a dotenv file under /run/ate/...) works across SNAPSHOT_FIDELITY_MEMORY restores without losing memory restore speed.

Workloads that read /run/ate/... on wakeup (or via a PostResume hook from #450, or a guest process runner like ate-env before spawning child processes) can load per-actor configuration after a memory restore.

Related issues

Activity

  1. brandonroyal commented on Nov 16, 2026

    @brandonroyal
    CollaboratorAuthor
  2. added
    kind/feature
    on Nov 16, 2026
  3. juli4n commented on Nov 17, 2026

    @juli4n
    Collaborator

    I think we need to think about this more generally. We need per-actor envs here, but we had many asks before about other fields (e.g #553 for images, #3866 for volume mounts, #2548 for network bandwith limits.

    If we add overrides one field at a time, each one needs its own inherit rules. I suspect the API will also be very subtle wrt not set values vs zero values, etc. We will also need rules about whether a change invalidates a golden snapshot or not.

    Maybe we need to re-consider the idea of just allowing the Actor resource to inline the template (using unionMember fields). When an actor is created, you can either specify the ObjectRef to the ActorTemplate or inline the template (it wouldn't be the ActorTemplate resource message proto but an equivalent).

    We discussed this in the past, the main concern was the Actor resource growing too much and degrading ate-apiserver. We could use Isolate to see how bad this is though.

    cc Zoe Zhao (@zoez7) Tim Hockin (@thockin)

  4. BenTheElder commented on Nov 18, 2026

    @BenTheElder
    Collaborator

    I would also nudge this toward the system info mount if possible, this pattern doesn't require throwing away memory and that's a big reason we already shipped it.

  5. mayawang commented on Nov 18, 2026

    @mayawang
    Collaborator

    Thanks for writing this up! For sandboxes that only need their own identity after resuming from a shared golden snapshot, the existing system info volume already works today, so I'd lean the same way as Ben.

    Tested on microVM with golden snapshots enabled: two actors resumed from the same golden snapshot each read their own name and UID from the system info mount, and that held across a later suspend and resume. A value the process cached at startup still showed the golden actor's value, matching the environment constraint in the issue.

    So identity on its own needs no API change, just the workload reading the mount after resume. Beyond identity, orchestrators that share one warm template across many sessions already need to pass per-actor settings, like a session ID. Projecting a small key-value map, or the #3617 annotations, into the system info volume seems like the smallest step for v1.1, with #450 if a guest needs a resume hook. That doesn't rule out Julian Gutierrez Oschmann (@juli4n)'s inlining idea for images and mounts, it just keeps memory snapshots working for the config case.

  6. mayawang commented on Nov 24, 2026

    @mayawang
    Collaborator

    Adding a concrete end-to-end CUJ from google/ax to help scope this for v1.2 (building on the SystemInfo check above, for discussion at the next community meeting).

    End-to-end AX flow

    In google/ax, many tasks share one warm ActorTemplate per profile (same container image and resource limits). What differs per task is a small set of non-secret runtime inputs: goal text, JSON config, MCP server list, optional session ID, workspace setup config (see google/ax#696), and task-level env values.

    1. Template: One shared ActorTemplate declares the base image, limits, and volume layout (with an optional golden memory snapshot).
    2. Create / Update / Resume: ax-server references that shared template and needs to attach a small, bounded map of per-actor inputs (non-secret; API keys stay outside the sandbox in the egress gateway). To support upgrading a task in place across resumes (Tasks should be upgradable google/ax#742), callers also need a clean way to update those values when resuming or modifying an existing actor.
    3. Guest read path (cold boot + golden restore):
      • Cold boot / ROOTFS restore starts a fresh process, where normal env vars would work.
      • Golden MEMORY restore resumes an already-running process (execve already ran), so envp cannot be updated. Writing per-actor entries into the host-generated read-only SystemInfo mount (/run/ate/...) works across both cold boots and memory restores without discarding the memory snapshot.
    4. Why separate per-task templates don't work today: Creating one template per task defeats golden snapshot reuse and bloats template storage. Swapping an actor's template on resume hits templateReplaced in ateapi, downgrading the first restore to SNAPSHOT_FIDELITY_VOLUMES and dropping installed tooling outside the workspace volume.
    5. Fork / isolation invariant: A forked or sibling actor must only see its own projected config on restore, never stale values cached from an earlier actor in the shared snapshot.
    6. Current workaround in AX: Today ax-server relies on an in-guest runner and pushes YAML over an HTTP port (POST /runner/v1alpha1/task; see all: push tasks to runners and remove the runner pull protocol google/ax#688 and runner: reply to a push only when the pushed work is complete, and delete the pushes channel google/ax#741). Moving per-actor config projection into Substrate core lets AX drop that temporary push path and run custom OCI images with minimal glue.

    Proposed minimal scope for v1.2

    • Keep it strictly to non-secret, bounded per-actor inputs (separate from full template inlining in Allow Actor resources to be self-contained #4005).
    • Regenerate the projected read-only files under the SystemInfo mount on Run and Restore (excluded from checkpoints, matching how actor identity already works).
    • Optional hook via Actor lifecycle hooks #450 (PostResume) if an already-running process needs a signal to reload updated files.

    Happy to walk through this briefly at the next community meeting to confirm the v1.2 direction and align on an implementation owner.

    cc Tim Hockin (@thockin) Benjamin Elder (@BenTheElder) Dmitry Berkovich (@dberkov) Jaana Dogan (@rakyll)

  7. rakyll commented on Nov 24, 2026

    @rakyll
    Collaborator

    Per actor environment would also simplify a significant number of BYOS integrations where actors have to be resumed with a new "work id" at resumption time. Today, we write a custom wrapper server around the actual worker binaries just to be able to pipe the dynamic variables.

  8. HavenXia commented on Nov 25, 2026

    @HavenXia
    Member

    Is it better to use per-actor config or per-tenant (atespace?) config?

  9. thockin commented on Nov 26, 2026

    @thockin
    Collaborator

    It is noted here, but sort of buried: There is no way to set an env on a running process from outside of that process. The practical implication is that setting a per-actor env var means you CANNOT use golden snapshots.

    To me, that seems like a high price to pay.

    Projected volumes exist BECAUSE of this limitation. But files in projected volumes represent fields in the API (e.g. the Actor's .metadata.name). If we want to add more projections, what field are we going to put them in? Annotations (#3617) seems plausible - is there something better?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

area/apikind/feature

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions