An oft-confusing passage for many Christians is James 2, which at first blush seems to contradict the salvation by grace alone through faith alone in Christ alone theme that Paul often uses in his epistles But rather than contradicting each other, James is quite indeed in accord with Paul on the matter of faith and its relationship to good works.
Simply put, the good works we do that God finds acceptable are those that flow from believing the promise of our salvation, and are empowered by the active, sanctifying work of the Holy Spirit in our lives.
Rather than faith and works being two distinct complementary intangible virtues that are up to the work and will of the individual Christian, our faith is alive, informed by, and animated by the work of Christ in our lives through the indwelling of the Holy Spirit in our hearts (Phil. 2:12-13).
Let's take a look at the text (James 2:14-26):
What good is it, my brothers, if someone says he has faith but does not have works? Can that faith save him? 15 If a brother or sister is poorly clothed and lacking in daily food, 16 and one of you says to them, “Go in peace, be warmed and filled,” without giving them the things needed for the body, what good  is that? 17 So also faith by itself, if it does not have works, is dead.
18 But someone will say, “You have faith and I have works.” Show me your faith apart from your works, and I will show you my faith by my works. 19 You believe that God is one; you do well. Even the demons believe—and shudder! 20 Do you want to be shown, you foolish person, that faith apart from works is useless? 21 Was not Abraham our father justified by works when he offered up his son Isaac on the altar? 22 You see that faith was active along with his works, and faith was completed by his works; 23 and the Scripture was fulfilled that says, “Abraham believed God, and it was counted to him as righteousness”—and he was called a friend of God. 24 You see that a person is justified by works and not by faith alone. 25 And in the same way was not also Rahab the prostitute justified by works when she received the messengers and sent them out by another way? 26 For as the body apart from the spirit is dead, so also faith apart from works is dead.
James clearly is talking about works that complete our faith. Our faith is not a mere pronouncement of belief or mental assent to a factual thing, it is an active lifestyle. Indeed, if you asked your run-of-the-mill demon, James insists, he'd say he believes in the risen Christ, and shudders in terror at Christ's sovereign and unconquerable reign.But yet while clearly our works flesh out and complete our faith, our faith itself, James insists, is animated by works. In a sense our faith fleshes out and completes our work, because our work is done in obedience to Christ in light of the promise of salvation and with an aim to please Him.
Let's look again closely at the analogy:
For as the body apart from the spirit is dead, so also faith apart from works is dead."Faith" is the body. "Works" is the spirit. Without the works animating the faith, the faith is dead and inoperative. But what works and whose working? Are not these works the result of the sanctifying and empowering grace of God in our lives, poured out by Christ through the Holy Spirit? (I Cor. 15:10)
Indeed, as Paul wrote in Philippians immediately after urging us to "work out your own salvation with fear and trembling" that we do so not of our own willpower but "it is God who works in you, both to will and to work for his good pleasure." (2:12-13)
These works are works of obedience that complete and live out our faith. They are things done by us not cooperating unto salvation but cooperating with God's to live out our salvation, that is, it's part of God's sanctifying work in our lives.
To see that more clearly, let's look at the example James gives of Rahab (see Joshua chapter 2).
Rahab was already saved by the promise of pardon from the Israelite scouts, who pledged they'd spare her life when Jericho was sacked. In faith she trusted their word was good and acted in a manner so as to save their lives and ensure their return to camp. She acted in faith that her promised temporal salvation at the hands of an erstwhile enemy would be honored at the time of judgment, that is when the scouts returned with a vast and mighty Israelite army to conquer Jericho.
Think about that: Rahab, a natural enemy of the Israelites, and a whore besides, trusted in the word of two Israelite soldiers, staking her life in double jeopardy. She trusted that the Israelite army would not kill her, and she trusted that her treason against Jericho was worth dying for at the hands of Jerichoan authorities should the Israelite siege fail and she be implicated in a pursuant investigation.
Rahab further acted out in faith by not reneging on her promise. She didn't change her mind and sell out the scouts by reporting them to the authorities when they had left the city.
And finally, and perhaps most importantly, Rahab agreed to and obeyed the instructions of the scouts about displaying the scarlet cord which would signify her apartment and hence prevent her, her family, and all occupants of her house from being destroyed in the siege (Joshua 2:18-21):
Behold, when we come into the land, you shall tie this scarlet cord in the window through which you let us down, and you shall gather into your house your father and mother, your brothers, and all your father's household. 19 Then if anyone goes out of the doors of your house into the street, his blood shall be on his own head, and we shall be guiltless. But if a hand is laid on anyone who is with you in the house, his blood shall be on our head. 20 But if you tell this business of ours, then we shall be guiltless with respect to your oath that you have made us swear.” 21 And she said, “According to your words, so be it.” Then she sent them away, and they departed. And she tied the scarlet cord in the window.Rahab's temporal salvation from destruction along with the rest of Jericho is but just a part and parcel of a greater salvation, her deliverance from sin and death. She is counted among the great "cloud of witnesses," the Old Testament heroes of faith listed in Hebrews chapter 11, after all. [Not to mention her place in Christ's lineage, see Matt 1:5]
No wonder James cited Rahab, as did the author of Hebrews, for hers is indeed a beautiful picture of our salvation.
Just as Rahab did not deserve salvation, neither do we. Just as Rahab lived among a culture hostile to God and His people, so do we. Just as Rahab went on to convert and marry into Israel, so are we who trust in Christ ingrafted into the true spiritual Israel. Just as Rahab's faith was completed by works of obedience, so is ours. And just as with Rahab, these works of obedience are lived out with trust in a promise that is clung to preciously, faithfully, and sometimes at risk of life and limb itself: the Gospel promise of our salvation.
It's a salvation that is true now in our justification before God, true now in our continuing sanctification and growth in Christ, and true in the future and final consummation of our salvation with the redemption of our bodies from death and corruption in the Resurrection. (Rom. 8:23)
Praise be to God, who saves us by His grace alone, through faith alone that He gives us to live out unto works of righteousness in emulation of His Son Jesus, to the glory of God alone.
Soli Deo gloria!