I understand from your sample files you want to enclose some code snippet inside a box.
Adding a rectangle shape over a group of paragraphs is a very bad idea because the paragraph may move with text flow while drawing shapes like rectangles will stay where you put them. There is no way to link shapes to text.
You apparently styled your code snippet wit Preformatted Text. All you need to do in addition is to slightly customise this paragraph style to add a border to it. Go to its Border
tab and configure the border to your liking.
However your files are plagued with direct formatting (manual formatting added to the paragraph outside the style mechanism) which will cause you trouble tuning the look of your text because manual formatting takes precedence over styling.
For your defence, M$ Word has a very poor notion of styles (knowing only of paragraph style) and all the rest must be applied manually.
I also noted you are not consistent in your styling: some snippets are Text Body with font face manually changed to monospace. These paragraphs don’t get the border when I configure Preformatted Text. Similarly, paragraph which should be Text Body are Preformatted Text and they are included in the boxed area.
Many paragraphs are Default Paragraph Style. While this is considered legitimate in M$ Word, this is a fault in Writer where common text should be Text Body. Default Paragraph Style is a “technical” style used to set various parameters shared by all other styles and should never be used over any real text in the document.
Don’t vertically space with empty paragraphs. Vertical spacing is an attribute of paragraph styles and should be defined there.
You won’t be able to format “comfortably” your document if you don’t follow a strict styling method. I recommend you read the Writer Guide for an introduction to styles.
To show the community your question has been answered, click the ✓ next to the correct answer, and “upvote” by clicking on the ^ arrow of any helpful answers. These are the mechanisms for communicating the quality of the Q&A on this site. Thanks!
In case you need clarification, edit your question (not an answer which is reserved for solutions) or comment the relevant answer.