Is it safe to eat sauteed onions left at room temperature?
After being cooked, the onions are much more subject to spoilage than they were whole.

After 2 hours (4 hours at the outside) cumulative at room temperature (well, between 40-140 F/4-60 C), they should be considered tainted and discarded, per standard official advise for perishable foods.

See also:
https://cooking.stackexchange.com/tags/food-safety/info