Foster rushed eight times for 38 yards before leaving, while Matt Schaub passed for 180 yards and a touchdown with an interception in the victory.
The game was held a week after two fans were shot outside San Francisco's Candlestick Park following the annual 49ers-Raiders preseason matchup. It came with increased security and new rules regarding tailgating in the parking lots around the stadium.
Alex Smith was just 2-for-6 for 17 yards and an interception, while Colin Kaepernick threw for 52 yards and a pick on 6-of-16 passing for San Francisco.
Houston also scored on Owen Daniels' 12-yard touchdown catch from Schaub and Troy Nolan's 73-yard interception return -- both in the second quarter, giving the Texans a 24-7 lead at halftime.