Very few 2 year olds are genuinely delightful, and 5 year olds are quite mercurial, they are still really little and can only manage so much really! And these are extraordinary times, you are currently seeing alllll of their behaviour with no ability to offload them at school, soft play, etc. So you'll have a different impression than you used to.
My 8yo DS is typically described as pleasant, sunny, lovely, charming, quiet, gentle by the adults in his personal/domestic life. This is a common theme from toddler days. He's always been that way.
At school he's described as recalcitrant, "a barrister" (talks his way out of any task he's been set), obstructive, difficult, distracting... he gets into playground fights and can be a real horror.
The difference between those two settings - home vs. school - is that at home, his leash is short and he knows his mother is cleverer than him/totally in charge. He can relax into his home life and knows exactly where the boundaries are, so he rarely tests them.
At school, the teachers are barely hanging on to their sanity, struggle to keep order, etc and have noticed that he's ahead cognitively/can read like a champ. So, they basically require very little from him day to day, and let him do whatever he pleases, every so often circling back to assess him - it's all very inconsistent, and he's clever, so he notices this and it annoys him.
So, my DS is constantly rattling the cage, trying to find someone who will tell him "no" at school... the teachers that have a personal relationship with him, who he respects, think he is wonderful. The teachers who require obedience and order, without showing him that they are trustworthy and worth following, think he's the worst.
Based on that experience... it's temperament influenced by environment, isn't it? And the temperament bit is luck, simply luck. You do have control over the environment, but you've also got to sort of let go and let God, there is only so much you can do, because the temperament is still in play.
I have found that for my DS, loads of sleep and rest are required for him to maintain his inner sunniness. He isn't as fussed regarding food, but for some kids, that's the key.