If someone has access into your Mac, they can do whatever the hell they wish to do. They can also install whatever kind of malware they want if that's their desire (provided they have enough computer knowledge to do so).
The best way to prevent this is to not be stupid and 1) put in a fairly secure password 2) don't spoil the password in the password hint thing 3) recommended, enable FileVault so that nobody can get to your data unless the password is known.
And obviously, don't be stupid and don't leave your computer in a public place alone for someone to infect I mean steal.