How to run a python script on the server, returning the results to the client
This is the precise use case for a geoprocessing service. Write your script and add it to a geoprocessing toolbox on the server as a script tool.
You can test it on the server while developing the script by hard coding the parameters. Once you're comfortable with your code, replace those hard coded parameters with arcpy.GetParameterAsText(), add to a geoprocessing toolbox as a script tool and publish to ArcGIS Server as either a synchronous (Execute Task) or asynchronous (Submit Job) service.
You can then use the geoprocessor (https://developers.arcgis.com/javascript/jshelp/intro_gp_overview.html) in the Javascript api to send a request to the service as well as handle the result.