A foil is a character who is written so that they contrast with another different character. This is done to make the character traits of the other character a lot more obvious. Foils are usually secondary characters, though they don’t need to be. They can be a part of your primary cast if you want them to.
There are a few things to remember when writing foils. The first of these is that if the foil is anything more than a background character which they most definitely should be, they should be round, dynamic characters rather than flat, stagnant characters. Every character should change as the plot progresses, the foil should be no exception.
The second of these is that the relationship between the foil and the other characters doesn’t really matter all that much. The foil can be friends, enemies, or just acquaintances with the other character. There are limitless possibilities.
The final thing you should remember is that although a foil will be a foil for at least a part of the plot, they can also be any of the other character types. They can be the antagonist and have their twisted morals contrast with the protagonists honour. The only character they can’t be is the protagonist because then who would contrast with the foil.