Bam Margera won't be anywhere near a 'Jackass' film set anytime soon, because he now has to stay away from its director, Jeff Tremaine, for a very long time.
Jeff, who claims Bam has recently threatened his life, was granted a restraining order Tuesday ... and it requires Bam to keep at least 100 yards away from Jeff for the next 3 years.
He's not allowed to contact Jeff in any way -- ditto for the director's wife and kids.
TMZ broke the story ... Jeff sought protection from his onetime pal after Bam recently went on a fuming rant against Tremaine and Johnny Knoxville.
JT claimed Bam was sending him increasingly disturbing messages, threatened his children and made a comment that Tremaine and Knoxville can "pencil in there [sic] death certificate."
The director said he feared for his family's and his own personal safety, so he filed for the restraining order ... and clearly presented enough evidence for the judge to sign off.
Bam's already been kicked off "Jackass 4," and the restraining order likely means a reunion is not in the works.