I'm not particularly knowledgeable on the topic of cryptocurrencies so it's possible that I've missed something obvious, but I still wonder what it is that stops a wallet from stealing from you. Wallets contain your private keys and they obviously have to use them to be able to send coin. So what stops a given wallet from stealing bitcoin from a user in the background without the user's knowledge?
What stops malware from being malicious?
What can you do to ensure that the wallet you are using is a secure way to access your bitcoin?
Use an open source bitcoin wallet, download from the original source and verify authenticity before use. If you understand code, review and build it yourself.
Obviously, if a person creates a wallet to steal bitcoin from users, they would not share its source code to be reviewed by everyone. Although, even that is possible and I have seen a few altcoin smart contracts that were created to steal user funds. Since not everyone is able to understand code and review it, in that case a few people ended up being victims before word got around.
Wallets contain your private keys and they obviously have to use them to be able to send coin.
That is indeed a very valid concern; you good sir have exercised thinking well.
Others have thought the same, and created hardware wallets to tackle exactly this threat!
Those are basically USB dongles with a button — which you have to physically press before it signs any transaction. So, this:
stealing bitcoin from a user in the background without the user's knowledge
does not work anymore — even when your green shiny well-known well-reviewed Open Source wallet software has been discreetly infected (for example, to show you one destination address, but substitute another when sending funds).
Crucially, hardware wallets are designed to hold private keys within, and are supposed to never share them with the host computer / wallet program. Spending request in — signed transaction out. This also protects your funds. For another example, you can now be OK with having to use a public computer with a crappy OS on it.
Maybe check out https://bitcoin.org/en/wallets/hardware/ — I'm sure you'll manage to do your own research from there.
Oh, and don't be fooled: just because it's a secure™ hardware chip — does not mean it can't be malicious in exactly the same way. Transparency requirements (e.g. Open Source firmware, bug bounty program, etc) still apply.