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 BlogCognition 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.
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.
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.
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.