Skip to content

Commit c863f33

Browse files
authored
Merge pull request #1388 from WolframResearch/feature/sandbox-path-options
Add sandbox path options to `WolframLanguageToolEvaluate`
2 parents 08a2c65 + 9b66d72 commit c863f33

File tree

3 files changed

+176
-144
lines changed

3 files changed

+176
-144
lines changed

.cspell.json

Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
{
2+
"words": [
3+
"AIAPI",
4+
"Astley",
5+
"Astro",
6+
"Autoload",
7+
"Bezier",
8+
"Birdnardo",
9+
"Chatbook",
10+
"Checkmark",
11+
"Checkmarked",
12+
"CICD",
13+
"ckpt",
14+
"clicktocopy",
15+
"CMYK",
16+
"Componentwise",
17+
"computabledata",
18+
"Connor",
19+
"contenttype",
20+
"datarepository",
21+
"Dbrx",
22+
"deepseek",
23+
"Deflatten",
24+
"Deinitialization",
25+
"Demi",
26+
"Dirtiable",
27+
"Docu",
28+
"dpkg",
29+
"EFAIL",
30+
"ENDARGUMENTS",
31+
"ENDRESULT",
32+
"ENDTOOLCALL",
33+
"ENTITLEMENTID",
34+
"evaliator",
35+
"Evaluatable",
36+
"FelisCatus",
37+
"Frameless",
38+
"Hennigan",
39+
"Iconize",
40+
"Iconized",
41+
"JDBC",
42+
"kaomoji",
43+
"Knowledgebase",
44+
"leadin",
45+
"Legended",
46+
"libgomp",
47+
"Linebreak",
48+
"Liouville",
49+
"LLMKit",
50+
"lmverbose",
51+
"Localizable",
52+
"Mathematica",
53+
"mathml",
54+
"mathworld",
55+
"MistralAI",
56+
"Mixtral",
57+
"Mousedown",
58+
"mtext",
59+
"Nemotron",
60+
"NFKC",
61+
"noicon",
62+
"noinit",
63+
"objs",
64+
"Ollama",
65+
"Omni",
66+
"OPENAI",
67+
"Overscript",
68+
"Paclet",
69+
"pacletreadonly",
70+
"Paclets",
71+
"Pagewise",
72+
"patt",
73+
"prefs",
74+
"preprocess",
75+
"Preprompt",
76+
"queryresult",
77+
"Qwen",
78+
"Rasterizer",
79+
"Reparse",
80+
"rerank",
81+
"reranking",
82+
"Rescrape",
83+
"Roboto",
84+
"RSNB",
85+
"schwag",
86+
"Screencast",
87+
"Scrollbars",
88+
"specialkeywords",
89+
"Streamable",
90+
"Struckthrough",
91+
"Stylesheet",
92+
"Subcontexts",
93+
"subpod",
94+
"Subsubitem",
95+
"Subsubsection",
96+
"Subsubsubsection",
97+
"Subsubsubsubsection",
98+
"Subsubtitle",
99+
"Subsuperscript",
100+
"tabletags",
101+
"tavily",
102+
"textbf",
103+
"textcontent",
104+
"textit",
105+
"TOOLCALL",
106+
"unbuilt",
107+
"Underoverscript",
108+
"Underscript",
109+
"Unformat",
110+
"Unformatting",
111+
"Unprotect",
112+
"Unsame",
113+
"unspaced",
114+
"URIQ",
115+
"URLQ",
116+
"usearch",
117+
"Wolfie",
118+
"wolframalpha",
119+
"wolframcloud",
120+
"wolframengine",
121+
"WOLFRAMINIT",
122+
"wolframresearch",
123+
"wolframscript",
124+
"wstp",
125+
"wxfl"
126+
],
127+
"ignoreRegExpList": [
128+
"\\:\\:[a-z]+", // message names
129+
"\\\\:[0-9a-f]+", // unicode characters
130+
"%[0-9A-F]{2}\\w+", // url encoded characters
131+
"1\\:eJ.+" // compressed data
132+
]
133+
}

.vscode/settings.json

Lines changed: 0 additions & 131 deletions
Original file line numberDiff line numberDiff line change
@@ -1,134 +1,3 @@
11
{
2-
"cSpell.words": [
3-
"AIAPI",
4-
"Astley",
5-
"Astro",
6-
"Autoload",
7-
"Bezier",
8-
"Birdnardo",
9-
"Chatbook",
10-
"Checkmark",
11-
"Checkmarked",
12-
"CICD",
13-
"ckpt",
14-
"clicktocopy",
15-
"CMYK",
16-
"Componentwise",
17-
"computabledata",
18-
"Connor",
19-
"contenttype",
20-
"datarepository",
21-
"Dbrx",
22-
"deepseek",
23-
"Deflatten",
24-
"Deinitialization",
25-
"Demi",
26-
"Dirtiable",
27-
"Docu",
28-
"dpkg",
29-
"EFAIL",
30-
"ENDARGUMENTS",
31-
"ENDRESULT",
32-
"ENDTOOLCALL",
33-
"ENTITLEMENTID",
34-
"evaliator",
35-
"Evaluatable",
36-
"FelisCatus",
37-
"Frameless",
38-
"Hennigan",
39-
"Iconize",
40-
"Iconized",
41-
"JDBC",
42-
"kaomoji",
43-
"Knowledgebase",
44-
"leadin",
45-
"Legended",
46-
"libgomp",
47-
"Linebreak",
48-
"Liouville",
49-
"LLMKit",
50-
"lmverbose",
51-
"Localizable",
52-
"Mathematica",
53-
"mathml",
54-
"mathworld",
55-
"MistralAI",
56-
"Mixtral",
57-
"Mousedown",
58-
"mtext",
59-
"Nemotron",
60-
"NFKC",
61-
"noicon",
62-
"noinit",
63-
"objs",
64-
"Ollama",
65-
"Omni",
66-
"OPENAI",
67-
"Overscript",
68-
"Paclet",
69-
"pacletreadonly",
70-
"Paclets",
71-
"Pagewise",
72-
"patt",
73-
"prefs",
74-
"preprocess",
75-
"Preprompt",
76-
"queryresult",
77-
"Qwen",
78-
"Rasterizer",
79-
"Reparse",
80-
"rerank",
81-
"reranking",
82-
"Rescrape",
83-
"Roboto",
84-
"RSNB",
85-
"schwag",
86-
"Screencast",
87-
"Scrollbars",
88-
"specialkeywords",
89-
"Streamable",
90-
"Struckthrough",
91-
"Stylesheet",
92-
"Subcontexts",
93-
"subpod",
94-
"Subsubitem",
95-
"Subsubsection",
96-
"Subsubsubsection",
97-
"Subsubsubsubsection",
98-
"Subsubtitle",
99-
"Subsuperscript",
100-
"tabletags",
101-
"tavily",
102-
"textbf",
103-
"textcontent",
104-
"textit",
105-
"TOOLCALL",
106-
"unbuilt",
107-
"Underoverscript",
108-
"Underscript",
109-
"Unformat",
110-
"Unformatting",
111-
"Unprotect",
112-
"Unsame",
113-
"unspaced",
114-
"URIQ",
115-
"URLQ",
116-
"usearch",
117-
"Wolfie",
118-
"wolframalpha",
119-
"wolframcloud",
120-
"wolframengine",
121-
"WOLFRAMINIT",
122-
"wolframresearch",
123-
"wolframscript",
124-
"wstp",
125-
"wxfl"
126-
],
127-
"cSpell.ignoreRegExpList": [
128-
"\\:\\:[a-z]+", // message names
129-
"\\\\:[0-9a-f]+", // unicode characters
130-
"%[0-9A-F]{2}\\w+", // url encoded characters
131-
"1\\:eJ.+" // compressed data
132-
],
1332
"files.trimTrailingWhitespace": true
1343
}

Source/Chatbook/Sandbox.wl

Lines changed: 43 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ $includeDefinitions := toolOptionValue[ "WolframLanguageEvaluator", "Inclu
2323
$sandboxEvaluationTimeout := toolOptionValue[ "WolframLanguageEvaluator", "EvaluationTimeConstraint" ];
2424
$sandboxPingTimeout := toolOptionValue[ "WolframLanguageEvaluator", "PingTimeConstraint" ];
2525
$evaluatorMethod := toolOptionValue[ "WolframLanguageEvaluator", "Method" ];
26+
$readPaths := toolOptionValue[ "WolframLanguageEvaluator", "AllowedReadPaths" ];
27+
$writePaths := toolOptionValue[ "WolframLanguageEvaluator", "AllowedWritePaths" ];
28+
$executePaths := toolOptionValue[ "WolframLanguageEvaluator", "AllowedExecutePaths" ];
2629
$cloudEvaluatorLocation = "/Chatbook/Tools/WolframLanguageEvaluator/Evaluate";
2730
$cloudLineNumber = 1;
2831
$cloudSession = None;
@@ -114,6 +117,9 @@ $$probableFailure = Alternatives[
114117
_Missing
115118
];
116119

120+
$$pathItem = _String | $$unspecified | ParentList | All | None | _Hold | _HoldComplete | _HoldCompleteForm;
121+
$$pathSpec = $$pathItem | { $$pathItem... };
122+
117123
(* ::**************************************************************************************************************:: *)
118124
(* ::Section::Closed:: *)
119125
(*Messages*)
@@ -126,13 +132,17 @@ Chatbook::InvalidEvaluatorProperty = "Invalid evaluator property: `1`.";
126132
WolframLanguageToolEvaluate // beginDefinition;
127133

128134
WolframLanguageToolEvaluate // Options = {
135+
"AllowedExecutePaths" -> Automatic,
136+
"AllowedReadPaths" -> Automatic,
137+
"AllowedWritePaths" -> Automatic,
129138
"AppendRetryNotice" -> False,
130139
"AppendURIInstructions" -> True,
140+
"IncludeDefinitions" -> Automatic,
141+
"Line" -> Automatic,
131142
"MaxCharacterCount" -> 10000,
132-
Line -> Automatic,
133-
Method -> Automatic,
134-
PageWidth -> Infinity,
135-
TimeConstraint -> 60
143+
"Method" -> Automatic,
144+
"PageWidth" -> Infinity,
145+
"TimeConstraint" -> 60
136146
};
137147

138148
WolframLanguageToolEvaluate[ code_, opts: OptionsPattern[ ] ] :=
@@ -189,9 +199,13 @@ wolframLanguageToolEvaluate[ code_, property_, opts_Association ] := Enclose[
189199
$appendRetryNotice = getOption[ "AppendRetryNotice" , opts ],
190200
$appendURIInstructions = getOption[ "AppendURIInstructions", opts ],
191201
$evaluatorMethod = getOption[ "Method" , opts ],
202+
$executePaths = getOption[ "AllowedExecutePaths" , opts ],
203+
$includeDefinitions = getOption[ "IncludeDefinitions" , opts ],
204+
$readPaths = getOption[ "AllowedReadPaths" , opts ],
205+
$sandboxEvaluationTimeout = getOption[ "TimeConstraint" , opts ],
192206
$toolOutputPageWidth = getOption[ "PageWidth" , opts ],
193207
$toolResultStringLength = getOption[ "MaxCharacterCount" , opts ],
194-
$sandboxEvaluationTimeout = getOption[ "TimeConstraint" , opts ],
208+
$writePaths = getOption[ "AllowedWritePaths" , opts ],
195209
$Line = getOption[ "Line" , opts ]
196210
},
197211
getProperty[ sandboxEvaluate @ preprocessCodeForTool @ code, property ]
@@ -238,8 +252,25 @@ getOption[ "Line", $$unspecified ] := $Line;
238252
getOption[ "Line", line_Integer? Positive ] := line;
239253
getOption[ "Line", line_ ] := throwFailure[ "InvalidOptionValue", "Line", line ];
240254

255+
getOption[ "IncludeDefinitions", $$unspecified ] := $includeDefinitions;
256+
getOption[ "IncludeDefinitions", include: True|False ] := include;
257+
getOption[ "IncludeDefinitions", include_ ] := throwFailure[ "InvalidOptionValue", "IncludeDefinitions", include ];
258+
259+
getOption[ "AllowedReadPaths" , paths_ ] := getAllowedPaths[ "AllowedReadPaths" , paths ];
260+
getOption[ "AllowedWritePaths" , paths_ ] := getAllowedPaths[ "AllowedWritePaths" , paths ];
261+
getOption[ "AllowedExecutePaths", paths_ ] := getAllowedPaths[ "AllowedExecutePaths", paths ];
262+
241263
getOption // endDefinition;
242264

265+
(* ::**************************************************************************************************************:: *)
266+
(* ::Subsubsection::Closed:: *)
267+
(*getAllowedPaths*)
268+
getAllowedPaths // beginDefinition;
269+
getAllowedPaths[ name_, $$unspecified ] := $DefaultToolOptions[ "WolframLanguageEvaluator", name ];
270+
getAllowedPaths[ name_, paths: $$pathSpec ] := paths;
271+
getAllowedPaths[ name_String, paths_ ] := throwFailure[ "InvalidOptionValue", name, paths ];
272+
getAllowedPaths // endDefinition;
273+
243274
(* ::**************************************************************************************************************:: *)
244275
(* ::Subsubsection::Closed:: *)
245276
(*getProperty*)
@@ -454,9 +485,9 @@ startSandboxKernel[ ] := Enclose[
454485

455486
kernel = ConfirmMatch[ LinkLaunch @ $sandboxKernelCommandLine, _LinkObject, "LinkLaunch" ];
456487

457-
readPaths = makeReadPaths @ toolOptionValue[ "WolframLanguageEvaluator", "AllowedReadPaths" ];
458-
writePaths = makeWritePaths @ toolOptionValue[ "WolframLanguageEvaluator", "AllowedWritePaths" ];
459-
executePaths = makeExecutePaths @ toolOptionValue[ "WolframLanguageEvaluator", "AllowedExecutePaths" ];
488+
readPaths = makeReadPaths @ $readPaths;
489+
writePaths = makeWritePaths @ $writePaths;
490+
executePaths = makeExecutePaths @ $executePaths;
460491

461492
(* Use StartProtectedMode instead of passing the -sandbox argument, since we need to initialize the FE first *)
462493
With[ { read = readPaths, write = writePaths, execute = executePaths },
@@ -517,11 +548,9 @@ $defaultReadPaths := $defaultReadPaths = Select[
517548
FileNameJoin @ { $BaseDirectory, "Autoload", "PacletManager" },
518549
FileNameJoin @ { $UserBaseDirectory, "Paclets" },
519550
FileNameJoin @ { $UserBaseDirectory, "Autoload", "PacletManager" },
520-
FileNameJoin @ { $UserBaseDirectory, "ApplicationData", "CloudObject", "Authentication" },
521-
FileNameJoin @ { $UserBaseDirectory, "ApplicationData", "Parallel", "Preferences" },
522-
FileNameJoin @ { $UserBaseDirectory, "ApplicationData", "Credentials" },
523-
FileNameJoin @ { $UserBaseDirectory, "ApplicationData", "Astro" },
551+
FileNameJoin @ { $UserBaseDirectory, "ApplicationData" },
524552
FileNameJoin @ { $UserBaseDirectory, "Knowledgebase" },
553+
FileNameJoin @ { $UserBaseDirectory, "Logs" },
525554
SystemInformation[ "FrontEnd", "DocumentationInformation" ][ "Directory" ],
526555
ExpandFileName @ URL @ $LocalBase
527556
},
@@ -547,6 +576,7 @@ $defaultWritePaths := $defaultWritePaths = Select[
547576
FileNameJoin @ { $UserBaseDirectory, "ApplicationData", "Credentials" },
548577
FileNameJoin @ { $UserBaseDirectory, "ApplicationData", "Astro" },
549578
FileNameJoin @ { $UserBaseDirectory, "Knowledgebase" },
579+
FileNameJoin @ { $UserBaseDirectory, "Logs" },
550580
FileNameJoin @ { ExpandFileName @ URL @ $LocalBase, "Resources" }
551581
},
552582
StringQ
@@ -607,7 +637,7 @@ makePaths[ All ] := If[ $OperatingSystem === "Windows", # <> ":\\" & /@ Characte
607637
makePaths[ None ] := { };
608638
makePaths[ paths_List ] := DeleteDuplicates @ Flatten[ makePaths /@ Flatten @ paths ];
609639
makePaths[ path_String ] := path;
610-
makePaths[ h: _Hold|_HoldComplete ] := makePaths @ ReleaseHold @ h;
640+
makePaths[ h: _Hold|_HoldComplete|_HoldCompleteForm ] := makePaths @ ReleaseHold @ h;
611641
makePaths[ ParentList|Inherited ] := ParentList;
612642
makePaths[ $$unspecified ] := Automatic;
613643
makePaths // endDefinition;

0 commit comments

Comments
 (0)