How to use selected text in apple script? I want to add text before and after it
Briefly, have your workflow accept Text from Any Application and check the box that is labelled something like Output Replaces Selection.

Then, all you need is a single Execute AppleScript action, in which you should replace any example code with this:

on run {input as text}
    return ["&lt;sometag&gt;", input, "&lt;/sometag&gt;"] as text
end run


which can also be written like this:

on run {input as text}
    return "&lt;sometag&gt;" &amp; input &amp; "&lt;/sometag&gt;"
end run


The workflow would need to be saved as a Service or Quick Action, and then be activated in System Preferences where other "Services" are listed.