Writing Samples often vary depending on the program. For instance, I had one that required the entire Master's thesis, another that required "The thesis abstract and one or more chapters", another that just wanted it to be less than 30 pages, and another that wanted it to be 15-20 pages in length. Still, other programs on my list recommend including a sample but give no specific length or content information as it's not required.
First things first, you probably don't want to turn in an entire thesis unless it's asked for by the program. Theses are long and adcoms probably won't want to read through it all. Better to give them a chapter or so that exemplifies your work. In my case, I reformatted my Findings chapter to meet the requirements as it hinted at methodology, research design, and my ability to think analytically about my topic. Since there were no citations in this chapter, I did not include a reference list, but you should if citations are present. Reference lists do not count against your page total.
The goal of the writing sample is to show adcoms that you are able to engage in the research process and academically communicate that process. It gives them the best sense of your writing style and the caliber of the work you will produce if in their department, as most academic programs still heavily rely on written deliverables as the main output (articles, papers, dissertations, etc).
It's different even within each department at the same university. Check out the webpage for each of the departments you're applying to. They should clarify the LOR format.
Though probably not in your case, I thought I would add one more to fuzzylogician's list.
By Email: The program provides an email address to which your writers will submit their letters directly. This is outside the application form. Only one of my programs has this requirement, but thought it was still worth mentioning.