Which is why Ian Fleming had James Bond originally armed with a .25 auto pistol.
During WWII, in which Fleming was a British SIS officer, their agents usually carried the smallest .25 autos possible if they were armed at all.
The hope was, if searched the tiny .25 might be missed and could be used to try to escape if they were arrested.
However, as above, a genuine spy isn't armed because this is proof positive he's an agent.
There are plenty of cases where agents talked their way out of trouble even after being given a search. When the secret police stop you, you are almost always searched.