Basically, don't accept friend invites from people you don't know. And, for Facebook/MySpace users, (this is equally important) if one of your friends sends you a friend request with absolutely no warning, ask them if they sent it before accepting it. Another thing to be aware of is if you receive more than one friend request for the same friend.
There are many ways to avoid becoming infected with Koobface. In general, don't be an idiot about what you do on your favorite social networking site(s). One more thing, to those of you who think this is only a Facebook/MySpace thing, I'll simply say, read the Wikipedia article.