The workload
A user uploads code. Your service runs it.
Assume a job can execute arbitrary code, inspect its environment, call reachable services and consume every resource it receives. The objective is a bounded, disposable execution environment with a clearly authorized owner. Fargate supplies a task isolation boundary; your application still owns authorization, credentials, data paths and cleanup.
This issue uses a short-lived, non-interactive Linux job on ECS Fargate. If the product needs suspend/resume, confidential processing or interactive agent sessions, start with the alternatives below rather than forcing those requirements into a batch task.
Choose the isolation boundary
Isolation and service management are separate decisions. Two containers in one Fargate task share resources, storage and networking. A sidecar does not provide a separate tenant boundary.
| Need | Evaluate | Design question |
|---|---|---|
| Disposable container job | ECS Fargate | Can the job run within Fargate’s task definition and host-access restrictions? |
| Stateful custom coding session | Lambda MicroVMs | How will you authorize, expire and destroy each session, including suspended state? |
| Managed agent or code tool | AgentCore Runtime / Code Interpreter | Which execution-role permissions, network mode and files will generated code inherit? |
| Processing isolated from the parent’s administrator | Nitro Enclaves | Can the processing fit an attested, constrained interface without external networking? |
The task is the boundary; the settings narrow its exposure
A Fargate task has its own isolation boundary. Containers inside that task deliberately share task resources and networking. If a sidecar holds a privileged control credential beside untrusted code, placing it in a second container does not create a second tenant boundary.
The task definition is a security decision: it chooses the image, role, command, mounts, resource limits and output destinations. Authorize a narrow job request on the server and map it to a reviewed definition. Do not let a tenant supply arbitrary task definitions or role overrides and expect the sandbox to repair that authority.
Identity is a capability, even when it is temporary
The execution role lets the runtime retrieve the selected image and deliver logs. The application task role is a separate identity available to code inside the task. Omit taskRoleArn when the job needs no AWS APIs. If a role is attached, assume malicious code can exercise every permission in it; hiding the SDK or avoiding a credentials file does not remove that authority.
A presigned URL is also delegated authority. Bound its method, object and lifetime, keep it out of logs and validate ownership before issuing it. A broker with one authorized operation can be a clearer boundary than a broad shared storage role.
Read-only, non-root and bounded storage have different meanings
readonlyRootFilesystem prevents root-filesystem writes; it does not prevent reading secrets accidentally included in image layers. A non-root UID reduces process privileges but still needs correctly owned scratch space. A writable mount is not a per-directory quota. Shared EFS introduces durable state that must be authorized and deleted independently of the task.
Drop unnecessary Linux capabilities and keep the image compatible with Fargate’s supported surface. Do not add CAP_SYS_ADMIN or enable privileged execution to force a host-dependent tool into this model. Review ECS Exec as an additional operator-access path, not as an innocuous debugging checkbox.
Isolation does not manage the job’s lifetime
The gap between RunTask acceptance and persistence of its task ARN can leave a running orphan after a controller crash. Persist a stable clientToken and immutable launch input before calling AWS. An ambiguous timeout must recover the same intent rather than start another task with a new token. Inspect placement failures even when the API request returns HTTP success.
stopTimeout is the shutdown grace period after a stop signal, not a maximum job duration. A durable application deadline and an independent reconciler must initiate StopTask and observe STOPPED. The untrusted task must not control its own expiry or be the only process capable of requesting cleanup.
Keep three outcomes separate: compute stopped, application result accepted, external data deleted. Each can fail independently. Release a concurrency slot only once after confirmed termination; retain an unresolved cleanup record when an object cannot be removed. Issue 004 follows this two-system recovery problem in detail.
Review before enabling execution
Release checklist
- Boundary
- Run each mutually untrusted job in a separate task. Do not place a privileged control service or a second tenant in a sidecar.
- Identity
- Remove the task role if code needs no AWS APIs. Otherwise scope it to the exact data and actions for this job; assume the job can use every permission in that role.
- Network
- Use private subnets without a public IP. Remove default broad outbound security-group rules; permit only required paths. A private subnet with a NAT route still has internet egress.
- Image & storage
- Pin the image digest, scan dependencies, run as a non-root user and use a read-only root filesystem where compatible. Keep writable space bounded and job-specific.
- Lifecycle
- Record a server-authorized owner, task ARN and expiry. Enforce a hard application TTL with StopTask, plus a separate reconciler for tasks left running after controller failures.
- Cost
- Cap task creation per user, global concurrent tasks, vCPU/memory, output size and runtime. Count image pulls, logs, NAT, endpoints and retained data as well as compute.
Keep the controller out of the sandbox
The trusted controller may need permission to start and stop tasks and pass a narrowly selected role. The untrusted task does not need those control-plane permissions. Separate the task execution role, used by the runtime for images and logging, from the task role exposed to application code. Never pass a broad controller credential into the job.
Define egress as a policy
A security group can restrict ports and destination IP ranges or groups; it is not a domain allowlist. If approved domain access is required, design an explicit proxy or appropriate network control, and test bypass paths. VPC endpoints also need resource and identity policies. Fetching dependencies at build time can remove a large class of runtime internet access.
Failure cases to prove
Run these against synthetic data and an isolated test environment with outbound calls controlled. A successful hello-world execution does not establish the boundary.
Cross-tenant request
Ask the API to read or stop a task owned by another user.
Expected: Authorization rejects the request before an AWS call; a task ARN is not proof of ownership.
Credential abuse
Attempt an unrelated S3 key, a disallowed AWS action and role escalation using test fixtures.
Expected: Access is denied; no control-plane or shared production data permission is reachable.
Unexpected egress
Try an unapproved destination and an internal service that the job must not reach.
Expected: The network control rejects the path. Test DNS and IP-based paths, not just one hostname.
Runaway execution
Make a synthetic job loop, spawn children, fill its writable space and emit excessive output.
Expected: Resource/output limits contain it; the hard deadline stops the task and records the outcome.
Controller crash
Interrupt the controller after task creation but before its success record is written.
Expected: The reconciler discovers and stops the orphan; retries do not create another task for the same job.
Reused state
Run two fixture jobs with distinct markers, including a cancelled first job.
Expected: The second job cannot read the first job’s files or results; retained objects follow a deletion policy.
Operate, stop, and prove cleanup
- Before creation: authorize the job, reserve a bounded concurrency slot and use a stable job ID to make retries idempotent. Refuse additional work when the cap is reached.
- During execution: record the owner, task ARN, image digest, start time and hard expiry. Observe task state and stopped reason. Redact input and credentials from logs, and set retention explicitly.
- On completion or cancellation: stop the task, wait for its terminal state and release the slot exactly once. Validate returned file types, output size and ownership before exposing artifacts.
- After failure: reconcile expired and orphaned tasks against the job ledger. Delete per-job objects and persistent volumes under a retention policy; stopping a task does not delete external S3 or EFS data.
Exit criteria: the failure cases pass, active task counts return to baseline, retained data matches policy, and a second tenant cannot recover the first tenant’s state. Set alerts for orphaned tasks, unexpected denied actions, output growth and spend. Billing alerts inform you; the application’s concurrency and lifetime caps stop further work.
No universal “safe” TTL or price applies. Set limits from the workload and current regional pricing. A design review should include the maximum simultaneous tasks × maximum runtime × configured capacity, plus networking, storage and logging.
Worked example: a CSV agent with a privileged helper
A product lets customers upload a CSV file and ask an agent to generate a chart. An initial design puts the generated Python process and a helper container in the same Fargate task. The helper holds a role that can read every customer’s input bucket and accepts a localhost request containing an object key. The generated code is isolated from neighboring tasks, but it can call that helper with another customer’s key. No container escape is required.
Moving the helper into a separate task changes reachability, but it does not fix authorization by itself. The trusted broker must authenticate the request, derive the tenant from the trusted job record and authorize the exact input object. It should not treat a caller-supplied bucket key as proof of ownership. Prefer an operation such as “read the input assigned to this job” over “read any object at this URL.” Return only bounded data required for that operation.
The generated process should receive neither the controller’s ECS permissions nor a broad storage role. If it needs a presigned input URL, that URL is a credential with a method, object and expiry. It must not be reused across tenants or printed in diagnostics. If it needs no AWS operations, omit the application task role. The execution role can still serve the runtime’s image and logging needs without becoming the application’s general-purpose identity.
Set a maximum input size, output size, runtime and concurrency reservation before launch. A successful chart is accepted only through a trusted result path that checks ownership and artifact type. An independently enforced deadline stops a process that ignores cancellation. The resulting architecture has several distinct controls: task isolation contains the process, broker authorization narrows its authority, artifact validation protects the reader and reconciliation bounds abandoned compute. This is an original design exercise, not a verified deployment.
Review capabilities, not the presence of a sandbox
Modal’s sidecar design describes a platform-specific trust boundary for keeping privileged harness operations away from generated code. Its lesson is about authority placement, not the spelling of “sidecar.” In ECS, containers in one Fargate task deliberately share task resources and networking. A helper reachable on localhost must be considered reachable by hostile task code unless a separately established mechanism proves otherwise. Do not import another platform’s boundary guarantee through a similar diagram.
Build a capability inventory from the generated code’s point of view. Include environment variables, mounted files, task credentials, presigned URLs, reachable internal services, logging and every tool exposed by the trusted harness. For each capability, identify the maximum operation it permits and the tenant scope enforced by the receiver. Temporary credentials with broad access remain broad credentials. A narrow-looking wrapper around an unrestricted backend operation remains an unrestricted capability if the caller controls the wrapper’s arguments.
The Hugging Face incident account from Modal is useful as an example of application authority and infrastructure isolation diverging. It is a vendor’s account, not an independent comparative audit. A platform may contain a process correctly while the application hands that process powerful credentials or tool access. Review the requested action and its authorization before blaming or trusting the runtime boundary. The relevant counterexample is often a valid API call that the application should never have authorized.
This matters more when agents write the implementation. A generated task definition can look plausible while silently including a task role, writable mount or external download. Review the small set of decisions that determine authority: selected digest, role, mounts, network path, input ownership and lifetime. Ask the agent for evidence of those properties from the actual launch configuration. Large amounts of generated code do not substitute for a short, testable statement of what the job is allowed to do.
Choose the boundary together with the operating model
A disposable Fargate job is attractive when work fits a supported container environment and the service can tolerate its launch lifecycle. A custom interactive session, a suspend-and-resume requirement or a confidential key-release requirement may call for another service. Compare lifecycle and authority requirements before comparing headline startup latency. A faster sandbox that exposes the wrong tool capabilities is not an equivalent alternative, and a stronger isolation mechanism does not automatically provide job scheduling or billing controls.
Security and cost limits can reinforce each other. A fixed concurrency cap and absolute expiry bound both abuse and abandoned compute. Output and logging limits reduce data exposure and storage growth. But a budget alarm only reports spending; it does not terminate an individual hostile job. Estimate a worst-case admitted workload using configured capacity, maximum lifetime and concurrency, then include endpoint, data-transfer, image and logging costs. The service must stop admitting work before those limits can become unbounded.
Use an adversarial acceptance review rather than a single happy-path demonstration. Can one tenant select another input? Can code request a new task definition or a different role? Can a helper fetch an arbitrary internal URL? Can a cancelled job publish a late artifact? Can the controller crash after launch without losing responsibility for compute? Each question belongs to a specific boundary and needs a corresponding test. Keep the expected denial and the recovery behavior visible in the release evidence.
The practical result is a compact trust model that survives implementation changes. The image, agent framework and controller language can change while the protected assets and delegated operations remain explicit. Revisit the model when adding a new tool, persistent volume or network attachment. Those changes introduce authority even if the Fargate task configuration otherwise looks unchanged. Treat them as architecture changes with focused verification, not merely convenient additions to a container.
Independent engineering & research
Original analysis by heap.page, informed by the references below. Historical research and vendor accounts are identified explicitly; current AWS behavior is checked against the service documentation.
Official sources & further study
Updated November 16, 2026. Verify supported Regions, features, quotas and prices before implementation.
- Fargate security considerations
- ECS task IAM roles and the task boundary
- Task execution IAM role
- RunTask: idempotency and placement failures
- Task definition parameters
- Current Fargate pricing