The phrase "keep oneself unstained from the world" contains the word "world" which James uses 5 times, this is the first. In all five cases, world carries a negative connotation. Basically world means the world's fallen system which is fundamentally opposed to God's Kingdom. James bids us to keep unstained from the world as part of practicing worthy religion. So what does this mean, to keep unstained from the world? Obviously we live in the world. It's not possible to totally isolate ourselves from the world, though it has been tried. The text seems to imply contact with the world at some level, but we are to keep from getting close enough or friendly enough to be stained.
Think of it this way- It's practically a necessity to eat pasta with marinara sauce. Who on earth would not agree? A person should never be so neglectful of his or her needs as to be deprived of heaven's food, but what if all we have to wear is a white shirt? How can we eat our pasta and sauce without messing up our shirt? Should we just not eat pasta? No, I say! That would be a travesty! We have to eat our pasta and succulent, garden fresh marinara sauce. But we have a white shirt on! I suggest eating the pasta ever so slowly and carefully. Perhaps placing a napkin over our shirt. Eat Penne or Rigatoni pasta with your sauce instead of spaghetti (which inevitably causes the most sauce stains due to the way a strand is slurped up). Take precautions, proceed slowly, be careful, pay attention to the possibility of getting stained by the sauce. Depriving oneself of pasta and marinara is not reasonably possible and, but you must be careful, lest your shirt become stained.
In like manner, we live in the world. We have a mission that involves impacting and transforming the world. When James speaks of keeping unstained from the world, think of how carefully we eat pasta covered with marinara while wearing a white shirt. We are not called to extract ourselves from the world, but rather influence it. How can we do this without becoming stained? We have to take precautions, proceed slowly, be careful, pay attention to the possibility of becoming stained by the fallen world. We can't afford to be reckless in our relationship with the world, that will only lead to sure stains and possibly much worse. Be aware of how easy it is to be stained, employ safeguards, and proceed with great care.