That's what they were bred for! They kept the rats out of the castles of Yore.
I used to have hamsters that were escape artists. I would always know where in the house they were because Tristan would be staring intently (behind the washer, under the fridge, etc). Thankfully though, he never wanted to harm them, he just wanted to find them and sniff them.