Can they have come from something you milled? If it was flour bugs, they can come from some grains you have previously milled.
Avoiding bugs entering externally shouldn’t be too hard, but it’s impossible to avoid flour bugs entirely since they live in what you put in the mill. Frequent inspection and cleaning helps. I also have some memory of Tom mentioning flour can be put in a freezer for some weeks to make sure no bugs survive for long term storage. May work on grains as well, but it require freezer room and patience.