In James 1:12-15, the Apostle talks about temptation and sin. He says that if you keep on overcoming in temptation, you will receive a crown of life from God one day. God promises that to all who love Him. That teaches us that if we love the Lord we will fight against all temptations to sin.
When a temptation comes to you, don't ask, "God, why did You send this temptation to me?" God never sent it. God doesn't tempt anyone. "Let no one say when he is tempted that God is tempting him. God doesn't tempt anyone." (James 1:13).
Who then is tempting you? It is Satan through the desires in your flesh. Because we have all indulged in the desires of our flesh for so many years from our childhood, Satan can use those desires to tempt us. When a country is at war, the enemy sends their agents secretly inside the country to cause destruction from within. The enemy fights on two fronts - at the battle front and also from within the country through its agents. So it is with Satan too. We must identify Satan's agents within us - the ungodly desires in our flesh, which are on the side of Satan - and put them to death. If you slay the agents of the enemy within, you will be strong to fight against Satan on the battle-front. It is only when you allow your mind to agree with a wrong desire that you sin. Until then the thought that comes to your mind is only a temptation. For example, as you are walking down the road, you see something that tempts you. That's not a sin. That is temptation. But when you look again at it, then you sin. The first look is temptation, the second look is sin. We cannot avoid the first look because we are living in a world which has so much evil all around us. But we can decide whether we agree with that evil or not.
It is similar to how a baby is conceived - which is the example used by the Holy Spirit here. When your mind agrees with the wrong desire in your flesh, it is like a woman agreeing to give her body to a man for sexual union. Then a conception takes place. But if the woman refuses to give herself to the man, there is no conception. Even so, if you reject the temptation and do not allow your mind to agree with the wrong desire, then there is no sin.
Someone has said, "You cannot prevent the birds from flying over your head, but you can stop them from making a nest in your hair. "The birds flying over your head are the temptations - many bad thoughts that come into your mind. Those are not sin, if you reject them immediately. Those are temptations. But if you choose to enjoy those bad thoughts for even a few seconds, then you have allowed the "birds" to start making a nest in your mind. Then you have sinned.
Satan tempted Jesus also by putting thoughts into His mind in the wilderness. But Jesus rejected them every time - and so He did not sin. So don't get discouraged because thoughts keep coming into your mind. They are only temptations. It is only when you enjoy those thoughts and accept them, that they become sin. This is very liberating for us to know that only when a conception takes place sin is born. If there is no conception, there is no baby. The final result of sin is spiritual death (James 1:15), and we should not be deceived about this (James 1:16).