AWS ECS Fargate Sandbox — Reference Infrastructure
AWS ECS Fargate Sandbox — Reference Infrastructure
NEL’s ECSFargateSandbox backend (see Sandbox Orchestration) runs each per-problem agent or code execution as an ECS Fargate task in your AWS account. The eval loop itself stays on whatever orchestrator host you choose (laptop, SLURM login node, Docker, K8s pod) — only the per-problem sandbox executes in ECS.
This page documents the reference Terraform that provisions the AWS-side infrastructure the ecs_fargate sandbox configuration expects. It is not a deployment guide for NEL itself.
The full implementation lives in terraform/; see terraform/README.md for the operator-facing walkthrough.
Where this fits
When the YAML sets region and leaves cluster unset, the backend reads /{ssm_project}/ecs-sandbox/config from SSM and populates cluster, subnets, security groups, role ARNs, S3 bucket, ECR repository, EFS, and SSH-sidecar secret ARNs — anything you set in YAML still wins.
What the Terraform creates
Per-region (one module instance per region in var.regions):
- VPC with public subnets across N AZs, internet gateway, route tables.
- ECS Fargate cluster with
containerInsightsandexecute-commandenabled. - Base task definition (per-task tasks clone & override this).
- ECR repository with a 500-image lifecycle policy.
- S3 staging bucket with public access block and 7-day expiry.
- CloudWatch log group (30-day retention).
- Secrets Manager entries for the SSH-sidecar keypair and Docker Hub credentials.
- SSM parameter
/{project}/ecs-sandbox/configwith the JSON the sandbox backend reads. - Optional EFS workspace filesystem for agent ↔ verifier file transfer.
Global (shared across all regions):
- IAM roles: ECS execution role, ECS task role, CodeBuild service role.
- IAM user + access key + custom policy for the orchestrator identity that submits
RunTaskandStartBuildcalls.
Prerequisites
- Terraform >= 1.5
- AWS credentials with permissions for VPC, ECS, ECR, S3, EFS, IAM, Secrets Manager, SSM, and CloudWatch Logs in every target region
Quick start
A single-region apply takes 3–5 minutes (mostly EFS mount-target propagation when enable_efs = true).
Wiring NEL to the provisioned cluster
Once apply completes:
-
Read the orchestrator credentials and feed them to your environment:
-
Reference the cluster in your benchmark config:
See
EcsFargateSandboxinsrc/nemo_evaluator/config/sandboxes.pyfor the complete schema.
State backend
Local state by default. To switch to a remote S3 backend, copy
terraform/stacks/ecs-sandbox/backend.tf.example
to backend.tf, supply your bucket and lock table, and run terraform init -reconfigure.
Security
- The ECS-task security group’s only ingress is
ssh_tunnel_sshd_portrestricted tovar.orchestrator_allowed_cidrs. The Terraform variable is required and rejects0.0.0.0/0; set it to the orchestrator host’s public egress CIDR(s). - The orchestrator-side LLM endpoint is not exposed on the public internet: the sandbox reaches it via the SSH session’s reverse tunnel (
-R), which terminates on127.0.0.1on the orchestrator host. - The orchestrator’s IAM access key lives in Terraform state. Either keep state local and treated as a secret, or use an encrypted remote backend with strict access control.
- The Terraform tree is scanned by SonarQube’s bundled IaC analyzer on every MR.
Tear down
ECR, S3, and Secrets Manager are configured to clean up immediately.