They look like moth larvae to me. Sometimes eggs get into hamster food and hatch. See this post about them here:
Hamster food and moths
I don't think they should hurt your hamster, seeing as meal worms are perfectly fine for hamsters and are, of course, a type of larvae. But, obviously, you shouldn't feed any more of that bag. In fact, I would throw it out straight away before the larvae turn into moths and you have a moth infestation in your house.
Freezing hamster food in future before feeding it (defrosted, obviously), can help prevent this in future.