Is it possible to sandbox a JavaScript function in C# code, execute it by passing in an argument such as an array, and return a result. No web browser involved here, this is not an Ajax or 'registerstartupscript' type of question.
Asked
Active
Viewed 3,192 times
2 Answers
3
From my own experience, for simple things Jurassic works like a charm and it's a JavaScript that can be used to run-time compile JavaScript and call functions, variables or whatever.
For example, taken from their own doc pages:
var engine = new Jurassic.ScriptEngine();
Console.WriteLine(engine.Evaluate("5 * 10 + 2"));
There're other options which involves embedding a full JavaScript engine, but AFAIK and reading your question's requirement, it seems like Jurassic should work in your scenario and you get the advantage of using a managed JavaScript compiler written in C# so there's no other dependency than the BCL from .NET and Jurassic itself.

Matías Fidemraizer
- 63,804
- 18
- 124
- 206
-
-
-
@MatíasFidemraizer, do you know if nodeService in dotnetcore can also run code in a sandbox? – JavaadPatel Oct 25 '19 at 11:10
-
1
Yes, you can!
JavaScript.NET is a .NET port of Google's V8 engine.
Another one I quite like is called Jurassic and it's available on nuget.

Oliver Bock
- 4,829
- 5
- 38
- 62

Matthew Layton
- 39,871
- 52
- 185
- 313