A gas turbine engine includes a compressor section and a turbine section together defining a core air flowpath. Additionally, a rotary component is rotatable with at least a portion of the compressor section and at least a portion of the turbine section. An electric machine is mounted coaxially with the rotary component and positioned at least partially inward of the core air flowpath along a radial direction of the gas turbine engine. A cavity wall defines at least in part a buffer cavity surrounding at least a portion of the electric machine to thermally insulate the electric machine, e.g., from the relatively high temperatures within the core air flowpath.