The prime minister of Algeria is defending his government's response to last week's attack on a natural gas plant that left 37 hostages dead. He says the Islamic militants who were behind the attack planned to blow up the facility and would have killed a lot more people if they hadn't been stopped.

The attack happened at a huge, internationally operated facility in the Sahara. And it underscores the dangers that energy companies face when they do business in politically unstable places.

A few years ago Luke Janger went to work overseeing oil wells at a base camp run by a major energy company in Chad. Security at the camp was minimal — just locals carrying billy clubs.

"There was no question in your mind that if the base was actually attacked in any way, especially by something similar to what's going on in Algeria, there is no way that we could have defended against them," Janger says.

The fifth week he was there, rebels attacked the capital 60 miles away, and for several days employees at the camp were unable to find out what was happening. The oil fields were a huge source of revenue for the government, and Janger knew they were vulnerable.

"Since the Chadian government couldn't keep the rebels out of the capital, it was clear they weren't going to be able to keep them out of base either," he says.

Eventually the company evacuated its employees, but Janger says for a year afterward he had trouble sleeping and drank a bit more than normal. The recent attack in Algeria brought some of the fear back to him.

"Immediately I think that there but for the grace of God went I, because it definitely could have happened. The location of the base, somebody could have hit us hard and fast," Janger says.

For as long as big energy companies have been doing business in foreign lands, they have had to contend with occasional instances of political instability. It's the price they pay for the riches they pull out of the ground in regions like the Middle East, Africa and Latin America. And companies pour a lot of resources into security measures.

"There are people in our companies who think about this all the time; that's what they do," says Steven Colville, president of the International Association of Drilling Contractors. He says the incident in Algeria is forcing companies to take another look at security.

"It makes everybody look again at what they're doing," he says. "It makes everyone assess those challenges. 'Let's add this into the scenario.' "

And attacks are virtually certain to happen again, says Jim Reese, president of the security company TigerSwan, which has a lot of experience overseas.

Reese says plants like the one in Algeria can be hard to protect. He says you have to set up concentric rings of security — fences inside fences. You have to use security cameras and dogs. It can be tough to do, he says.

"The size of these organizations are very difficult to secure," Reese says. "Security can be a very expensive line item in a budget for a lot of corporations, but it's got to be done."

And even fences aren't enough. Reese points out that members of terrorist groups have sometimes managed to infiltrate plants by getting hired. Reese says the local population can help alert a company to threats it faces, but the company needs to stay in the community's good graces. That means providing jobs to locals and being a good steward of the environment.

"So it's not just putting a fence up and, 'OK, we're safe now.' There's a very holistic approach, what I would call the unblinking eye, that needs to be [part of] your security," Reese says.

Copyright 2016 NPR. To see more, visit http://www.npr.org/.