So I want to use a fake name for my book, not my real name. How do I ensure that editors or agencies don't take advantage of that or play a trick when it comes to the credits of the book? How do I make sure that there are no 'loop holes'?
I don't know how the publisher would take advantage of you.
Your contract with the publisher (or agent) will be under your real name. Only then is the contract legally binding. In that contract, you will specify that you want to publish under a pseudonym (and whether your real identity must be held confidential by the publisher).
"Credit" will go to your pseudonym, as that is the name under which critics, book stores, and readers will know "you". Copyright will belong to you, the author.
Again, I don't see a way for the publisher to take advantage of you (in a way that they couldn't with a non-pseudonymous author).
Pseudonyms, and also professional ghostwriters hired to help a celebrity push out a book, are such common things that publishers and agents have contracts and legal departments to accommodate them. As was said in the other answers, the person getting paid being different from the name on the cover is "business as usual".
Probably the only threat to a pseudonymous author is if they become too popular, or are already famous under another name. JK Rowling and Steven King were both discovered because their (already famous) writing was recognized. In the case of King, a bookstore clerk played detective after recognizing King's style. Rowling was supposedly discovered through computer analysis.
Both were good-natured about it. King actually encouraged the bookstore clerk to write his discovery as a mystery article and agreed to be interviewed. Rowling always manages to be the most gracious billionaire on the planet. But they had nothing to lose except the pleasure of seeing their books appreciated without the shadow of their own fame. King's publisher had actually refused to publish more than one Steven King book per year out of fear of competition from his own novels, so the pseudonym had been a compromise. Rowling wanted to break out of the schoolboy wizard albatross she'd created for herself.
However, recently "Elena Ferrante" was outed by a journalist who claimed because of the popularity of her novels she was a public figure who has no right to privacy, but she was not a known name or a public figure. She just valued her privacy. The publishing world made a big fuss to shame the journalist, but it's likely the shame-campaign created more publicity than the original article.
In all 3 cases, the publishers attempted to shield the authors, but also in all 3 cases the publishers were the Achilles heel leaving a paper trail of large payments and legal documents that led back to them. In the case of King and Rowling, the authors had used their same agents and publishers, making their identities easier to confirm.
True anonymity may not be possible in the internet age, not if it is combined in any way with success. If your pseudonym is about aesthetics, don't fear the publisher. However, if the pseudonym is about maintaining true anonymity, unfortunately there are no guarantees.
Pen names are pretty common, and most publishers have policies of their own for them. You should be fine, it'd take a pretty poor publisher to somehow exploit an author's wish to have a nom de plume and turn it into a legal loophole.