Great sentence! It is mostly correct. Here are a couple of small tips to make it even better in general writing:
- Start with a capital letter: You already did this with "You" — good job!
- The comma and "but": Using a comma before "but" is correct when you join two ideas like this.
- "a branch" or "branches": If you mean sloths hang from any branch, use "branches" (plural). If you mean one specific branch, "a branch" is okay. Many people say "branches" because it is more general.
- "hanging" explains how they sleep: That word is correct — it tells us what the sloths are doing while sleeping.
- End punctuation: The exclamation mark (!) is fine if you want the sentence to sound excited. A period (.) is also okay if you want it calm.
Corrected (a bit more general):
You sleep in your bed, but sloths sleep upside down, hanging from branches like little hammocks!
Simpler versions for reading aloud:
- You sleep in your bed. Sloths sleep upside down on branches like little hammocks.
- You sleep in your bed, but sloths sleep upside down on branches.
Nice work — your sentence was already clear and fun!