In Josefina Lopez’s play “Detained in the Desert,” the setting is haunted by ghosts composed of bone.

At La Jolla Playhouse, Teatro Máscara Magica’s production of the 2010 work is at times vexed by men (and women) made of straw.

Lopez, the Chicana playwright and screenwriter perhaps best known for “Real Women Have Curves,” confronts the issue of illegal immigration with rhetorical fists flying. “Detained” spins a story of lives colliding in the Arizona desert, spurred on by prejudice, revenge and the corrosive effects of draconian immigration laws.

Teatro Máscara Magica, the Playhouse’s latest resident theater company (and a venerable San Diego institution), musters a 17-member cast and an involving sense of atmosphere for the production: John Iacovelli’s urban-meets-badlands set and Dave Rivas’ layered, radio-centric sound design are especially effective.

And the show, directed by longtime Teatro artistic chief William Virchis, is clearly driven by deep feeling all around. After Thursday’s opening-night performance, Lopez — who had one of her first scripts produced by San Diego’s Playwrights Project as a teen-ager — told of writing “Detained” in a burst of inspiration after working with the volunteer group Border Angels and visiting the desert graves of would-be immigrants.

Not all of that passion translates successfully into the play, and one reason is that some characters are either conceived or portrayed a little too cartoonishly to be convincing.

That feels particularly true of the central figure Lou Becker (Charles Maze), an unctuous, immigrant-baiting radio host who defends prejudice in the name of patriotism.

There’s no doubt that commentators who spread equally repugnant viewpoints are on the air right now. And yet when such polarizing figures show up in a play (as with the Old Globe’s revival of “Inherit the Wind” last year), they’re sometimes sketched as too-obvious windbags.

That kind of characterization can make playgoers feel good about detesting them. But arguably the real danger in life (and real drama in theater) stems from demagogues who are complex and sophisticated enough to conceal their zealotry in some semblance of seeming reasonableness.

If the approach in “Detained” is meant as over-the-top satire, it’s not necessarily clear from the production’s overall tone, or from the acting, which spans a range of styles. One of the most affecting performances, in fact, is also one of the most low-key and natural, by Rivas as the compassionate volunteer Enrique (based on the real-life founder of the Border Angels).

Still, Maze turns in a committed (and very physical) performance as Becker, who finds himself — like the people he had once condemned — suddenly struggling to survive. So does the young, principled Latina Sandra Sanchez (a fiery and affecting Alix Mendoza), whose path leads to an unlikely meeting with Becker in the desert.

Lopez’s characters often are not exactly who they seem (even to themselves), a fact that does inject some needed complexity. The show’s use of magical-realist elements, including skeletons who skulk silently and spookily, also brings a sense of mood and mystery. Their presence is fitting for a play that is like an emotional X-ray of a very volatile subject.