The kingdom of Shanshan included the strategic walled town of Kroran (or Loulan) near the northwest corner of Lop Nur, next to the then outflow of the Tarim River into Lop Nur (40° 9’ N, 89° 5’ E). The site of Kroran covered about 10.8 hectares (27 acres) with a Buddhist pagoda about 10 metres (33 feet) high, numerous houses, and irrigation ditches. It also include Charklik which is located near the modern town of Ruoqiang to the south-west of Lop Nur. It also includes the kingdoms of Cherchen (now Qiemo), as well as Niya further to the south-west. It has been suggested that the name "Cherchen" may have been derived from Shanshan.
Because of its position on what became the main routes from China to the West, controlling both the Southern Route between Dunhuang and Khotan, and the main Silk Route from Dunhuang to Korla Kucha and Kashgar during the Former Han and Later Han; control of the kingdom was regularly contested between the Chinese and the Xiongnu. The Xiongnu repeatedly contested the Han Chinese for control of the region until well into the 2nd century CE.
In 77 BCE, the Chinese envoy Fu Jiezi was sent to kill the Loulan king, named Chang Gui or An Gui (嘗歸 or 安歸), after several Han envoys were kidnapped and killed. He arrived on the pretext of carrying gold and valuables to the outer states and intending to give a presentation to the king, but stabbed the Loulan king to death while he was drunk. The king's younger brother Wei-tu-qi (尉屠耆) was then installed as the king of Loulan by the Han ruler, and the kingdom was renamed Shanshan.
The newly installed king requested the presence of Han forces in Yixun (伊循), due to his fear of retribution from the sons of the assassinated king in Loulan. Chinese army officers were therefore sent to colonise the area, and an office of commandant was established at Yixun.
In 25 CE it was recorded that Shanshan was in league with the Xiongnu. In 73 AD, the Han army officer Ban Chao went to Shanshan with a small group of followers, which was also receiving a delegation from the Xiongnu. Ban Chao killed the Xiongnu envoys and presented their heads to the King, after which King Guang of Shanshan offered his allegiance to Han.