Steven Moffat suggested that the avatars work in a factory. Attempting to make it different from other factories featured in the series, Matthew Graham proposed to set the story in a monastery, an idea of which Moffat greatly approved.
Steven Moffat indicated that the Doctor should be proactively investigating the Flesh, rather than happening upon the St John's monastery by chance.
Matthew Graham wanted the Gangers to be scary, but not monsters who wanted "to take over the world for the sake of it". He wanted them to appear relatable to the audience as they were humans who deserved rights.
The monastery was inspired by The Name of the Rose (1986), while the Gangers were influenced by The Thing (1982).
Originally, the facility would have housed a much larger complement of both staff and Gangers, but these numbers were cut back both for budgetary reasons and to accentuate the atmosphere of claustrophobia and paranoia.