As Joseph was sold into slavery to Potiphar, the captain of the guard in Egypt, he was soon put in charge of all that Potiphar had owned. Joseph was a handsome man, so Potiphar’s wife wanted to sleep with him, but Joseph wouldn’t allow it. In fact, she continued to chase him, but he told her that his master had held nothing back from him except for her, because he was his wife.
Joseph worked diligently to stay in innocence with regard to Potiphar’s wife. He not only, of course, didn’t sleep with her, but it says that he wasn’t even willing to be with her.
And though she spoke to Joseph day after day, he refused to go to bed with her or even be with her.
Genesis 39:10
I think Joseph understood the danger of temptation. He knew that if he were to be tempted by her, he could fall into the trap. Even putting himself in the same area as her would be dangerous, so he wanted to stay far from her.
This is right in terms of avoiding sin. Not only should we be ready to run when it presents itself to us, but we should avoid even being in the same vicinity as the temptation. We should try to know ourselves, to work to understand where Satan will try to attack us, and flee from those places. Joseph did this correctly and we should follow his example.