Lillie uses repels to get around without being attacked by wild Pokémon. But repels only work when you have a Pokémon in your first party slot that has a higher level than the wild Pokémon in the area. So what does Lillie have, since she’s not a trainer? She has Nebby.
When you finally obtain the version legendary, AKA Nebby, it is at level 55. Far higher than most wild Pokémon in the game. Given, there’s no guarantee Nebby was at that level as a Cosmog, especially since Cosmog typically evolves into Cosmoem at level 43 unless the evolution is cancelled.
However, we see Nebby use some kind of teleportation in the intro cutscene, and Teleport happens to be a move that Cosmog learns at level 23, so we know Nebby has to be at least level 23 at the start of the game. Nebby then continuously gains levels over the course of the story, staying just ahead of the wild Pokémon and keeping Lillie safe.
When he’s in the bag, of course.