I have learned to vacuum seal anything that could bring in with it grain weevils.
No air = baby's don't live long enough to grow, make more babys.
Freeze works if you have the room.
Beans, rice, sugar, salt all get vac sealed in plastic bag and put away in cool dry place for long term storage.
Once in a while I'll forget to seal a bag of flour and then we are doing what you did. Anything in a cardbord box is suspect.
They eat right through those. I saw a pair of pinholes in a 4lb crystal sugar sack. I don't think he liked what he found so he chewed out again.
Jiffy corn muffins, pizza mix we dumped a bunch of.
Pasta we mostly dumped into a plastic strainer with fairly large square holes.
Sifted the bugs right out of my wifes elbow macaroni and tri colored rotini.
Spaghetti I keep in a plastic container.
Bayer makes a home bug spray that drys and leaves a film. If a bug steps on it they die.
So our pantry got cleaned out, sprayed, left to dry before we put things away.
Countertop gets treated every spring to keep little ants and things down.