Most people know Kumail Nanjiani as computer coder Dinesh on HBO's "Silicon Valley." But over the past year, the star has transformed his body to play swordsman Kingo Sunen in the upcoming Marvel movie, "The Eternals," thanks to a super strict diet and fitness routine.
"I found out a year ago I was going to be in Marvel's 'Eternals' and decided I wanted to transform how I looked," Nanjiani, 41, wrote in an Instagram caption Dec. 16.
And that's exactly what he did.
Nanjiani worked with "the best trainers and nutritionists paid for by the biggest studio in the world," according to his Instagram post.
And while he has "sort of learn[ed] to enjoy" the daily workouts, "the diet is the hardest thing," he said on ABC's "Jimmy Kimmel Live" on Friday.
Nanjiani cut out all refined sugars (like table sugar and high fructose corn syrup) from his diet, though he still ate fruit (which contains natural sugar or fructose).
And for the year, "I've had almost no carbs at all," Nanjiani told Kimmel.
From Monday through Friday, Nanjiani would eat a very low-carb diet, and then "over the weekend, you eat as much as you want," he told Men's Health Australia in November.
One of Nanjiani's trainers, David Higgins, encouraged him to have a "cheat meal" on the weekend. His favorite indulgent, carb-laden meal is Pakistani food, including "biryani, naan bread and tons of rice," he said.
Nanjiani also received "delicious and healthy meals" from Matthews Street Catering, a catering business that services the film industry, he wrote on Instagram.
As for fitness, Nanjiani had been casually exercising with trainer Lance Callahan for six years, but he amped things up before filming. He also started exercising with Grant Roberts, a Canadian trainer who's known for training celebrities before physically demanding roles, including Hilary Swank ahead of "Million Dollar Baby."
Roberts "made me understand true physical pain for months and months," Nanjiani wrote on Instagram. Their routines consisted of lifting weights and using electronic stimulation (aka "e-stim") technology, which allows you to target a muscle and increase the contractions during an exercise.
Almost every day while filming, Nanjiani would work out with Higgins. Their workouts helped him get "strong, limber and injury free," he wrote in the caption. "I can almost touch my toes now."
In addition to the physical payoff, Nanjiani said he got hooked on the mental benefits of exercise. "When I'm exercising, I'm not thinking about anything else," Nanjiani told Men's Health Australia. "It's like meditation."
Nanjiani acknowledged, however, that this routine isn't sustainable. "I wish it was just like a video game where you just, like, hit 'save' and then like, alright, now I look like this every day," he told Kimmel.
Nor is his routine realistic for most people who don't have a movie budget to devote to health and fitness. "I'm glad I look like this, but I also understand why I never did before," Nanjiani wrote. "It would have been impossible without these resources and time."
Nanjiani isn't the only celebrity to ditch carbs to get in shape for an action role. Fellow action movie star Linda Hamilton said in October that she didn't eat carbs for a year while training for her role in "Terminator: Dark Fate."
And rigid, low-carb diets have gained popularity recently, with many celebrities praising the high-fat, high-protein and extremely low-carb ketogenic diet.
However, while diets that restrict carbohydrates (typically "low carb" means 20 to 60 grams a day) have been shown to lead to weight loss, severely limiting carbs can lead to side effects, like headaches, weakness, fatigue and muscle cramps, according to the Mayo Clinic.
Like this story? Subscribe to CNBC Make It on YouTube!