I think it was achieved by two nuclear armed countries openly amassing their assets in the region for months. Any conflict between peer non-nuclear nations would have probably began with the country in Iran’s position sinking those carriers. Thanks to US and Israeli nukes, they were free to start killing people without fear of getting surprised.
It is unlikely that Iran decided to not sink US carriers because of fear of nuclear retaliation. It is much more likely that before the air attack started, Iran's leadership preferred not to do anything that could make an attack more likely, such as attacking carriers. And after the invasion started, they would have loved to attack carriers but did not have the military capability to do so.