Williams began brightly on the Arthur Ashe Court as she raced into a 4-1 lead within 10 minutes.
Spaniard Sanchez responded by holding her next service game, only for Williams to win the next two games to take the first set.
However, a double fault from Williams at the start of the second set handed Sanchez the advantage. She failed to take that opportunity though, double-faulting three times to allow Williams to level the set up at two games apiece.
The set then went with serve up until 5-4 in Williams's favour. That is when the American struck to book her place in round three with a 6-4 success.
She will now face Ekaterina Makarova for a place in round four.