Twenty others were in critical or serious condition, some believed to be suffering heatstroke or dehydration, and taken to hospital.
Police did not say where the vehicle came from, but confirmed that the driver was in custody.
They are investigating a possible people-smuggling offence.
The US immigration department is trying to establish the victims' status.
San Antonio Police Chief William McManus said in a media briefing that the bodies were discovered after a call from a Walmart employee, who had been approached by someone from the truck asking for water.
Video footage from the store showed a number of vehicles arriving to pick up some of the survivors, he added.
Several others may have managed to escape on foot into the woods nearby.
Local fire chief Charles Hood said they had arrived at the scene just after midnight to find eight people dead in the back of the trailer truck, which had no functioning air conditioning and no signs of water inside.
The survivors had heart rates of over 130 beats per minute and were very hot to touch. In addition to 20 in critical condition, eight others of less severity were taken to hospital.
He confirmed at least two of the victims were school-age children.
"We're very fortunate that there weren't 38 of these people who were all locked inside this vehicle dead," he added.