First of all, you sound like you are a true believer in God and His Son, the Lord Jesus Christ. I was glad to read that you know the Jesus is “the way, the truth, and the life” (John14:6), for He is the Savior for everyone who trusts in Him for salvation (John 3:16 and Acts 16:31).

I feel for you as you struggle with sinful thoughts. These thoughts are not of God, for they come from the “enemy within” (the FLESH, which is the “sinful nature” you were born with…. Psalm 51:5 and Romans 7:14-20). As a believer in Christ, you also have a “new nature,” which God gave to you when you were “born again” through faith in His only begotten Son (see John 3:1-8, 14-16; 1 Peter 1:22-23; and 2 Peter 1:2-4). These “two natures” (the “sin nature” and the “divine nature”) are in conflict with one another, for the “sin nature” wants to keep you in bondage to sin (see Romans 7:21-24), while the “new nature” wants you to stay focused on Jesus Christ through the Word of God so you can be set free from sin (see John 8:31-32, 36 with Psalm 119:11).

What is the way of victory over SIN and these evil thoughts that keep coming to mind? Thankfully, the moment you trusted in Christ as your Savior you were given the Holy Spirit to live inside of you (Ephesians 1:13). He is the “power within you” that will give you the victory if you yield to Him. We read of this in the following two passages: “For the law of the Spirit of life in Christ Jesus has MADE ME FREE FROM THE LAW OF SIN and death” (Romans 8:2). “I say then, walk in the Spirit, and you shall not fulfill the lust of the flesh. For the flesh lusts against the Spirit, and the Spirit against the flesh; and these are contrary to one another, so that you do not do the things that you wish. But if you are led by the Spirit, you are not under the law” (Galatians 5:16-18). This means if we allow the Holy Spirit to lead us, He will defeat the flesh within, and we will experience FREEDOM FROM SIN!

In your question you said that you “TRY to do good,” yet you are defeated. This is exactly what the Apostle Paul wrote about in Romans 7:14-20. He tried to do what would please God, but he failed. He tried not do what God hates, and he failed! Why? Because he was TRYING to do good in his own power and strength. He had “confidence in his flesh.” But at some point, he discovered “in me, that is, in my flesh, dwells no good thing.” In time he also learned that the Spirit of God dwells in him so he could be free from sin by the Spirit’s power. Philippians 3:3 tells us to “have no confidence in the flesh” but we can have full confidence in the Spirit! So, instead of TRYING you should be TRUSTING!

When a wicked thought comes into your mind you should immediately think, “Okay, this is coming from my sinful nature.” If you continue to dwell on those bad thoughts, you will be defeated. But if you turn to the Lord in real dependence and rely on the Holy Spirit, He will give you the victory (read again Galatians 5:16-18.) Satan, the “enemy without,” will seek to put temptations before you to cause you to think evil thoughts and sin, but the “Spirit within you” will put thoughts of the Lord Jesus before you to set you free from sin. This battle can be won, but only the Holy Spirit can “win the battle” as you turn the battle over to Him. (DO) (748.1)