@larkup/sandbox 0.1.12 → 0.1.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +24 -0
- package/dist/docker-runner.d.ts +0 -7
- package/dist/docker-runner.js +2 -1
- package/dist/local-runner.js +2 -1
- package/dist/python-execution.d.ts +2 -0
- package/dist/python-execution.js +64 -0
- package/dist/remote-exec.js +2 -15
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,29 @@
|
|
|
1
1
|
# @larkup/sandbox
|
|
2
2
|
|
|
3
|
+
## 0.1.14
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- f670ddc: Add validated structured aggregation plans, retain schema units and value definitions, preserve Python literals when repairing escaped code, and avoid unchanged execution retries. Surface bounded analysis limitations rather than unverified results.
|
|
8
|
+
|
|
9
|
+
## 0.1.13
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- 0ded907: Stabilize source-grounded research and analytical answers.
|
|
14
|
+
|
|
15
|
+
- Rank relevant schemas independently of upload order, use matching data-dictionary definitions, and honor authoritative source-to-table links.
|
|
16
|
+
- Rerank complementary source evidence, preserve bounded supporting passages, and permit one focused research refinement.
|
|
17
|
+
- Route full-population calculations, integrity checks, and independent rankings to deterministic analysis; validate requested group coverage and isolate failed output from answer evidence.
|
|
18
|
+
- Capture notebook-style Python expressions consistently across local, Docker, and remote runtimes, and render final DataFrames as complete structured results.
|
|
19
|
+
- Compact older user context in the background without retaining old assistant claims as facts or removing saved history.
|
|
20
|
+
- Distinguish source formats from export requests and reuse verified analysis tables for exports.
|
|
21
|
+
- Cache live model availability, reject retired selections, honor the selected reasoning model, and report the provider's actual model ID instead of a silent cross-model fallback.
|
|
22
|
+
- Preserve atomic PDF figure annotations and headings, validate passage locators with source quotes, and require the full underlying data for requested analytical charts.
|
|
23
|
+
- Serialize missing/nonfinite analytical cells as JSON null so sparse joins remain usable structured answers.
|
|
24
|
+
- Preserve derived analysis fields during schema repair, require verifiable group/chart coverage, and finish completed structured results without regenerating their facts as prose.
|
|
25
|
+
- Preserve individual user constraints through browser/server compaction and report provider-budget failures explicitly without exposing account details.
|
|
26
|
+
|
|
3
27
|
## 0.1.12
|
|
4
28
|
|
|
5
29
|
### Patch Changes
|
package/dist/docker-runner.d.ts
CHANGED
|
@@ -1,10 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Docker-based sandbox runner.
|
|
3
|
-
*
|
|
4
|
-
* Uses `dockerode` to manage ephemeral containers for code execution.
|
|
5
|
-
* Each execution spins up a container, runs the code, captures output +
|
|
6
|
-
* generated files, then auto-removes the container.
|
|
7
|
-
*/
|
|
8
1
|
import type { DockerConfig, ExecutionRequest, ExecutionResult, SandboxHealthCheck } from './types.js';
|
|
9
2
|
export declare function checkDockerHealth(): Promise<SandboxHealthCheck>;
|
|
10
3
|
export declare function buildSandboxImage(onProgress?: (msg: string) => void): Promise<void>;
|
package/dist/docker-runner.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { pythonExecutionSource } from './python-execution.js';
|
|
1
2
|
/**
|
|
2
3
|
* Docker-based sandbox runner.
|
|
3
4
|
*
|
|
@@ -205,7 +206,7 @@ except ImportError:
|
|
|
205
206
|
# Execute user code with robust error handling
|
|
206
207
|
# ============================================================
|
|
207
208
|
try:
|
|
208
|
-
|
|
209
|
+
${pythonExecutionSource(JSON.stringify(Buffer.from(code).toString('base64')), ' ')}
|
|
209
210
|
|
|
210
211
|
# Auto-save any remaining matplotlib figures
|
|
211
212
|
try:
|
package/dist/local-runner.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { pythonExecutionSource } from './python-execution.js';
|
|
1
2
|
import { randomUUID } from 'node:crypto';
|
|
2
3
|
import { promises as fs } from 'node:fs';
|
|
3
4
|
import os from 'node:os';
|
|
@@ -255,7 +256,7 @@ except ImportError:
|
|
|
255
256
|
try:
|
|
256
257
|
_larkup_stdout = StringIO()
|
|
257
258
|
with redirect_stdout(_larkup_stdout):
|
|
258
|
-
|
|
259
|
+
${pythonExecutionSource(JSON.stringify(Buffer.from(code).toString('base64')), ' ')}
|
|
259
260
|
_larkup_output = _larkup_stdout.getvalue()
|
|
260
261
|
sys.stdout.write(_larkup_output)
|
|
261
262
|
if not _larkup_output.strip():
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/** Notebook-style expression capture shared by local and remote Python runtimes. */
|
|
2
|
+
export function pythonExecutionSource(encodedExpression, indentation = '') {
|
|
3
|
+
return `import ast as _larkup_ast, base64 as _larkup_base64
|
|
4
|
+
def _larkup_display_expression(value, final=False):
|
|
5
|
+
if value is not None:
|
|
6
|
+
table = globals().get('larkup_table')
|
|
7
|
+
if final and callable(table) and hasattr(value, 'columns') and callable(getattr(value, 'to_dict', None)) and callable(getattr(value, 'to_string', None)) and not globals().get('_LARKUP_PRESENTATION_EMITTED', False):
|
|
8
|
+
table('Analysis results', value, columns=list(value.columns))
|
|
9
|
+
return
|
|
10
|
+
formatter = globals().get('_larkup_print_result')
|
|
11
|
+
if callable(formatter):
|
|
12
|
+
formatter(value)
|
|
13
|
+
else:
|
|
14
|
+
print(repr(value))
|
|
15
|
+
_larkup_source = _larkup_base64.b64decode(${encodedExpression}).decode('utf-8')
|
|
16
|
+
try:
|
|
17
|
+
_larkup_tree = _larkup_ast.parse(_larkup_source, filename='analysis.py', mode='exec')
|
|
18
|
+
except SyntaxError as _larkup_original_error:
|
|
19
|
+
import io as _larkup_io, tokenize as _larkup_tokenize
|
|
20
|
+
_larkup_lines = _larkup_source.splitlines(keepends=True)
|
|
21
|
+
_larkup_offsets = [0]
|
|
22
|
+
for _larkup_line in _larkup_lines:
|
|
23
|
+
_larkup_offsets.append(_larkup_offsets[-1] + len(_larkup_line))
|
|
24
|
+
_larkup_protected = set()
|
|
25
|
+
try:
|
|
26
|
+
_larkup_fstring_depth = 0
|
|
27
|
+
for _larkup_token in _larkup_tokenize.generate_tokens(_larkup_io.StringIO(_larkup_source).readline):
|
|
28
|
+
_larkup_kind = _larkup_tokenize.tok_name[_larkup_token.type]
|
|
29
|
+
if _larkup_kind == 'FSTRING_START':
|
|
30
|
+
_larkup_fstring_depth += 1
|
|
31
|
+
if _larkup_token.type in (_larkup_tokenize.STRING, _larkup_tokenize.COMMENT) or _larkup_fstring_depth:
|
|
32
|
+
_larkup_start = _larkup_offsets[_larkup_token.start[0] - 1] + _larkup_token.start[1]
|
|
33
|
+
_larkup_end = _larkup_offsets[_larkup_token.end[0] - 1] + _larkup_token.end[1]
|
|
34
|
+
_larkup_protected.update(range(_larkup_start, _larkup_end))
|
|
35
|
+
if _larkup_kind == 'FSTRING_END':
|
|
36
|
+
_larkup_fstring_depth -= 1
|
|
37
|
+
except (_larkup_tokenize.TokenError, IndentationError):
|
|
38
|
+
raise _larkup_original_error
|
|
39
|
+
_larkup_repaired = []
|
|
40
|
+
_larkup_pos = 0
|
|
41
|
+
while _larkup_pos < len(_larkup_source):
|
|
42
|
+
if _larkup_source[_larkup_pos:_larkup_pos + 2] == chr(92) + 'n' and _larkup_pos not in _larkup_protected:
|
|
43
|
+
_larkup_repaired.append(chr(10))
|
|
44
|
+
_larkup_pos += 2
|
|
45
|
+
else:
|
|
46
|
+
_larkup_repaired.append(_larkup_source[_larkup_pos])
|
|
47
|
+
_larkup_pos += 1
|
|
48
|
+
_larkup_candidate = ''.join(_larkup_repaired)
|
|
49
|
+
if _larkup_candidate == _larkup_source:
|
|
50
|
+
raise _larkup_original_error
|
|
51
|
+
_larkup_tree = _larkup_ast.parse(_larkup_candidate, filename='analysis.py', mode='exec')
|
|
52
|
+
_larkup_expression_indices = [index for index, node in enumerate(_larkup_tree.body) if isinstance(node, _larkup_ast.Expr) and not (isinstance(node.value, _larkup_ast.Call) and isinstance(node.value.func, _larkup_ast.Name) and node.value.func.id == '_larkup_auto_present')]
|
|
53
|
+
_larkup_final_expression = _larkup_expression_indices[-1] if _larkup_expression_indices else -1
|
|
54
|
+
for _larkup_index, _larkup_node in enumerate(_larkup_tree.body):
|
|
55
|
+
if isinstance(_larkup_node, _larkup_ast.Expr):
|
|
56
|
+
if _larkup_index == 0 and isinstance(_larkup_node.value, _larkup_ast.Constant) and isinstance(_larkup_node.value.value, str):
|
|
57
|
+
continue
|
|
58
|
+
_larkup_node.value = _larkup_ast.Call(func=_larkup_ast.Name(id='_larkup_display_expression', ctx=_larkup_ast.Load()), args=[_larkup_node.value, _larkup_ast.Constant(value=_larkup_index == _larkup_final_expression)], keywords=[])
|
|
59
|
+
_larkup_ast.fix_missing_locations(_larkup_tree)
|
|
60
|
+
exec(compile(_larkup_tree, 'analysis.py', 'exec'), globals(), globals())`
|
|
61
|
+
.split('\n')
|
|
62
|
+
.map((line) => indentation + line)
|
|
63
|
+
.join('\n');
|
|
64
|
+
}
|
package/dist/remote-exec.js
CHANGED
|
@@ -1,17 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
* Shared execution plumbing for every cloud sandbox adapter (E2B, Vercel
|
|
3
|
-
* Sandbox, Modal, Daytona, Fly Sprites, Northflank).
|
|
4
|
-
*
|
|
5
|
-
* Each of those providers exposes the same primitive — "run this shell
|
|
6
|
-
* command inside my sandbox and give me stdout/stderr/exitCode back" — but
|
|
7
|
-
* with a different SDK shape (commands.run, runCommand, exec, ...). Rather
|
|
8
|
-
* than re-implement file staging + artifact capture per provider, adapters
|
|
9
|
-
* plug their SDK's exec call in as a `RemoteExecFn` and hand it to
|
|
10
|
-
* `runScriptedExecution`, which stages inputs, runs the code, and reports
|
|
11
|
-
* back files written to an output directory (mirroring what the Docker
|
|
12
|
-
* adapter gets for free via a bind mount). Providers with a native filesystem
|
|
13
|
-
* API can stage large files without embedding them in a process command.
|
|
14
|
-
*/
|
|
1
|
+
import { pythonExecutionSource } from './python-execution.js';
|
|
15
2
|
import { getMimeType } from './mime.js';
|
|
16
3
|
/** Default per-execution timeout for remote adapters when a request doesn't specify one. */
|
|
17
4
|
export const DEFAULT_TIMEOUT_MS = 30_000;
|
|
@@ -59,7 +46,7 @@ try:
|
|
|
59
46
|
except ImportError:
|
|
60
47
|
pass
|
|
61
48
|
_larkup_encoded_code = ${JSON.stringify(encodedCode)}
|
|
62
|
-
|
|
49
|
+
${pythonExecutionSource('_larkup_encoded_code')}
|
|
63
50
|
try:
|
|
64
51
|
if 'plt' in globals() and plt.get_fignums():
|
|
65
52
|
plt.show()
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@larkup/sandbox",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.14",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
"e2b": "^2.39.0",
|
|
47
47
|
"@vercel/sandbox": "^3.0.0",
|
|
48
48
|
"modal": "^0.11.0",
|
|
49
|
-
"@daytona/sdk": "^0.
|
|
49
|
+
"@daytona/sdk": "^0.227.3",
|
|
50
50
|
"@browserbasehq/sdk": "^2.17.0",
|
|
51
51
|
"playwright-core": "^1.62.1",
|
|
52
52
|
"@fly/sprites": "^0.2.0",
|