Menu
AWS Architecture Blog·November 20, 2026

Scaling AI Coding Agents with Cloud-Based macOS Environments on EC2 Mac

Cognition leveraged Amazon EC2 Mac instances to scale Devin, their AI software engineer, for macOS application development. This article details the architectural decisions and system design choices made to provide on-demand, virtualized macOS environments, including state management via disk snapshots, secure networking with user-space Ethernet gateways, and optimized guest image preparation for rapid session startup.

Read original on AWS Architecture Blog

Cognition faced the challenge of enabling their AI coding agent, Devin, to build and test Apple applications, which inherently requires macOS and Xcode. Instead of managing physical Mac hardware, they opted for Amazon EC2 Mac instances to provide scalable, cloud-based macOS development environments. This approach allows Devin to provision a fresh macOS VM in under a minute, significantly accelerating the development and testing cycle for iOS and Mac apps.

Architecting Scalable macOS Workspaces

The core architectural challenge was to provide each Devin session with a dedicated, isolated macOS environment that behaved like other cloud workspaces, while adhering to Apple's licensing constraints (allowing up to two macOS guest VMs per physical Mac). Cognition designed a system where EC2 Mac Dedicated Hosts run two isolated macOS guest VMs, each serving an active Devin session. This maximizes resource utilization of the underlying hardware.

  • Bare Metal Instances: EC2 Mac instances run as bare metal, allowing the use of Apple's Virtualization framework directly.
  • Dedicated Hosts: While instances run on Dedicated Hosts, Cognition separates the life of a Devin session from the host, enabling multiple sessions per day per host.
  • Auto Scaling: For dynamic capacity, an Auto Scaling group manages the allocation and release of Dedicated Hosts.

State Management with Disk Snapshots

To handle the asynchronous nature of Devin's work and allow idle sessions to release VMs without losing state, Cognition implemented a disk snapshot system. This system runs as a separate process on the host, managing disk I/O for the VMs. When a guest shuts down, the storage process persists pending writes and uploads an updated snapshot to Amazon S3. This allows sessions to be resumed from snapshots in seconds, significantly improving capacity utilization.

💡

Adapting Storage for macOS Virtualization

The use of Network Block Device (NBD) attachments was crucial here, as the Apple Virtualization framework didn't support `vhost-user` (used for Linux VMs). Adapting the existing snapshot system with an NBD frontend allowed Cognition to maintain a consistent storage design across different operating systems.

Secure Network Access with User-Space Gateway

To enforce session-specific network access rules and protect host infrastructure, Cognition built a user-space Ethernet gateway for each Mac VM. This custom gateway handles Ethernet frames, validates addressing, and passes accepted IP packets to a tunnel interface on the host where `pf` (macOS packet filter) rules apply access policies. This approach avoided conflicts with Apple's default NAT implementation and provided granular control over network traffic.

AWSEC2 MacVirtualizationmacOSAI AgentsCloud ArchitectureScalabilityInfrastructure as Code

Comments

Loading comments...