Bug introduced in 10.0 and persisting through 11.3

A support case with the identification [CASE:3618534] was created.

[...] I filed a report with our development team raising the issues [...]

$EvaluationEnvironment was supposed to be a panacea for: Good way to discriminate between Mathematica/PlayerPro/CDFPlayer

But from my experience it is not full working in a "desktop" area.

The remaining question is: I don't have time to check everything, could you? :)


  • "WebEvaluation"

  • "WebAPI"

  • "WebForm"

  • "Subkernel" (fixed somewhere around 11.2)

I'm not sure

  • "Session" - it works well but all others that fail return "Session" so tough to count on it

  • "WebLoad" not clear in comparison to "WebAPI"

  • "RemoteSession", "WebServer", "CloudCDF", "PlugInCDF", "WSTP" - not tested

Not working:

  • "CDF"

  • "Script"

  • "Scheduled"


1 Answer 1


The bug is confirmed and a workaround is available in the linked topic.

Nothing to do here now so I will move the code part of the question to this wiki answer to remove it from an unanswered stack and make a terse list on top.

Code samples to reproduce specific values of $EvaluationEnvironment:

  • "WebEvaluation"

  • "WebAPI"

      APIFunction[{"x" -> String}, $EvaluationEnvironment &]
    ] //  URLExecute[#, {"x" -> "100"}, "JSON"] &
  • "WebForm"

    CloudDeploy[FormFunction[{"x" -> String}, $EvaluationEnvironment &]]
  • "Subkernel"

    ParallelEvaluate[{$KernelID, $EvaluationEnvironment}, Kernels[]]

  • "WebLoad"

    CloudDeploy@Delayed@{$EvaluationEnvironment, DateList[]}

  • "CDF"

     SystemOpen @ CDFDeploy[
     , Dynamic[{RandomReal[], $EvaluationEnvironment}, UpdateInterval -> 1]
  • "Script"

    path = FileNameJoin[{$HomeDirectory, "Desktop", "test.wl"}];
    Export[path, "Print @ $EvaluationEnvironment", "Text"];
    Import["! math.exe -script " <> path , "Text"]
  • "Scheduled"

     RunScheduledTask[Print@$EvaluationEnvironment, {2}]
  • $\begingroup$ As of 12.0 RunScheduledTask[Print@$EvaluationEnvironment, {2}] prints "Session" $\endgroup$
    – M.R.
    Commented Jan 7, 2020 at 17:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.