She knew that when the spies came to her house that she needed to do whatever it took to protect them. Even when the king's messengers came looking for the spies. She had taken the time to hide them on the roof under some flax that she was drying. When flax is dry it is gathered in bundles that stand on end about four feet high that she could have hid them behind or she could have piled a bunch of fresh flax on top of them as the laid flat underneath it. Then she went back down unfaraid of what might happen to her if she was found out, she lied to the messengers and sent them off on a wild goose hunt for the spies.
It was before she lowered the spies down that Rahab made her confession that she believed that their God was the one true God. This was her heart felt conviction that all other gods were false and her heart had drawn her to wanting to serve the one true God. Her heart heard the truth in the stories about Him and what He did for the Hebrews. She didn't fear Him like the rest of the city, instead she saw Him as her Savoir that would free her from her bondage.
She also made them promise that she and her family would be kept safe during the invasion. They agreed with a couple of conditions:
1. She and her family were to stay inside her house.
2. If any of her family was not in her house they could not be held accountable for what might happen to them.
3. The scarlet cord that she used to lower the spies down on was to hang outside her window down the wall as a marker for them.
The interesting thing about the cord is that it was strong enough to hold the weight of the men as they repelled down the wall. That would be very thick and at a distance it might look like blood flowing down the wall. In a way this was Rahab's Passover. Just like in Egypt on the first Passover where the Hebrews were safe as long as they were inside the house with the blood of the land paint around their door. She and her family would be safe due to her confession as long as they were inside her house and the scarlet cord was hanging from her window.