A class environment is, imo, the hardest place for even a well a dog to reliably demonstrate behaviour it has been taught

Good classes/teachers will emphasis the fact that they are primarily delivered to teach the owners/handlers to train the dogs - and a key part of the training that the dog receives is away from home between classes.
Referred to as "taking training on the road", it basically means that once you have a reliable behaviour at home (low distraction) you then go somewhere else with a higher level of distractions, and train the same behaviour all over again.....and then go somewhere with higher distractions again
Molo's behaviour in agility demonstrates this really well - when we first started going, I couldn't keep his attention between obstacles and he would run off to sniff or go and say hello to spectators

Over time, he has learnt to remain focused on me and will now reliably remain with me around an agility course at our usual training venue. If we go elsewhere though, he is still distracted - even though he understands the commands and knows what is expected of him

I need to take his agility training "on the road", so that he learns to do the same thing in higher distraction environments
