The attack took place 60 km south of the eastern city of Ajdabiya, said General Ahmad al-Mesmari, spokesman for Haftar's self-proclaimed Libyan National Army.
One fighter was beheaded, General Mesmari said, noting the attack bore the hallmarks of IS.
The jihadist group claimed responsibility for the attack soon after via its propaganda agency Amaq.
Authorities launched an investigation into the attack and were bidding to track down the perpetrators, Mesmari said.
Despite the loss of its coastal stronghold of Sirte in December 2016, IS remains active in Libya.
Various jihadist groups including IS have exploited the chaos that has reigned in Libya since the downfall of dictator Moamer Kadhafi to gain a foothold in the country.
The country has two rival governments: a United Nations- backed one in the west and a rival administration backed by Haftar's forces in the east.