Director J.J. Abrams ordered a closed set for most of the filming to avoid the secrets of the plot becoming public, so Pegg and his co-stars had to hide under cloaks and travel around the studio in tarpaulin-covered golf buggies.
The heightened security system was put in place following publication of a photograph of Zachary Quinto in uniform - and Pegg was terrified he would be kicked off the movie after taking a sly picture of himself in his Scotty outfit.
He tells British TV show This Morning, "I thought I was going to get arrested. I took the picture with my phone because my wife was with me in Los Angeles and I thought I would show her the picture when I got home. She had been on the set anyway.
"But as I was leaving the Paramount lot that night, I was convinced that someone would say, 'Excuse me, sir'... and stop me and arrest me."