A key to understanding James is found in John 6. Jesus said that the work of God is believing in the Son. As such James is saying that true faith will result in the fruition of that belief hence will result in God working in a person’s life. Hence a liar had faith to offer his son (Abraham) and a prostitute saved spies by lying (Rahab).
In both cases it does not speak about works of the law since murder and false witnessing are both wrong according to law. Hence it speaks about God producing righteousness in them. It is about His work. Hence faith without works is dead except it is not the Christian’s work but God’s work in him. After all in Phillipians 1 God says he who began a good work shall finish it.