@larkup/sandbox 0.1.12 → 0.1.15

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 CHANGED
@@ -1,5 +1,35 @@
1
1
  # @larkup/sandbox
2
2
 
3
+ ## 0.1.15
4
+
5
+ ### Patch Changes
6
+
7
+ - 95093cc: Preserve escaped Python source on strict tokenizers and refine shared data browsing, source artwork, groups, and controls.
8
+
9
+ ## 0.1.14
10
+
11
+ ### Patch Changes
12
+
13
+ - 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.
14
+
15
+ ## 0.1.13
16
+
17
+ ### Patch Changes
18
+
19
+ - 0ded907: Stabilize source-grounded research and analytical answers.
20
+
21
+ - Rank relevant schemas independently of upload order, use matching data-dictionary definitions, and honor authoritative source-to-table links.
22
+ - Rerank complementary source evidence, preserve bounded supporting passages, and permit one focused research refinement.
23
+ - Route full-population calculations, integrity checks, and independent rankings to deterministic analysis; validate requested group coverage and isolate failed output from answer evidence.
24
+ - Capture notebook-style Python expressions consistently across local, Docker, and remote runtimes, and render final DataFrames as complete structured results.
25
+ - Compact older user context in the background without retaining old assistant claims as facts or removing saved history.
26
+ - Distinguish source formats from export requests and reuse verified analysis tables for exports.
27
+ - 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.
28
+ - Preserve atomic PDF figure annotations and headings, validate passage locators with source quotes, and require the full underlying data for requested analytical charts.
29
+ - Serialize missing/nonfinite analytical cells as JSON null so sparse joins remain usable structured answers.
30
+ - Preserve derived analysis fields during schema repair, require verifiable group/chart coverage, and finish completed structured results without regenerating their facts as prose.
31
+ - Preserve individual user constraints through browser/server compaction and report provider-budget failures explicitly without exposing account details.
32
+
3
33
  ## 0.1.12
4
34
 
5
35
  ### Patch Changes
@@ -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>;
@@ -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
- exec(${JSON.stringify(code)})
209
+ ${pythonExecutionSource(JSON.stringify(Buffer.from(code).toString('base64')), ' ')}
209
210
 
210
211
  # Auto-save any remaining matplotlib figures
211
212
  try:
@@ -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
- exec(compile(base64.b64decode(${JSON.stringify(Buffer.from(code).toString('base64'))}), 'analysis.py', 'exec'))
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,2 @@
1
+ /** Notebook-style expression capture shared by local and remote Python runtimes. */
2
+ export declare function pythonExecutionSource(encodedExpression: string, indentation?: string): string;
@@ -0,0 +1,70 @@
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
+ # Keep offsets stable without feeding escaped separators to strict tokenizers.
26
+ _larkup_token_source = _larkup_source.replace(chr(92) + 'n', ' ')
27
+ try:
28
+ _larkup_fstring_depth = 0
29
+ for _larkup_token in _larkup_tokenize.generate_tokens(_larkup_io.StringIO(_larkup_token_source).readline):
30
+ _larkup_kind = _larkup_tokenize.tok_name[_larkup_token.type]
31
+ if _larkup_kind == 'FSTRING_START':
32
+ if _larkup_fstring_depth == 0:
33
+ _larkup_fstring_start = _larkup_offsets[_larkup_token.start[0] - 1] + _larkup_token.start[1]
34
+ _larkup_fstring_depth += 1
35
+ if _larkup_token.type in (_larkup_tokenize.STRING, _larkup_tokenize.COMMENT) or _larkup_fstring_depth:
36
+ _larkup_start = _larkup_offsets[_larkup_token.start[0] - 1] + _larkup_token.start[1]
37
+ _larkup_end = _larkup_offsets[_larkup_token.end[0] - 1] + _larkup_token.end[1]
38
+ _larkup_protected.update(range(_larkup_start, _larkup_end))
39
+ if _larkup_kind == 'FSTRING_END':
40
+ _larkup_fstring_depth -= 1
41
+ if _larkup_fstring_depth == 0:
42
+ _larkup_protected.update(range(_larkup_fstring_start, _larkup_end))
43
+ except (_larkup_tokenize.TokenError, IndentationError):
44
+ raise _larkup_original_error
45
+ _larkup_repaired = []
46
+ _larkup_pos = 0
47
+ while _larkup_pos < len(_larkup_source):
48
+ if _larkup_source[_larkup_pos:_larkup_pos + 2] == chr(92) + 'n' and _larkup_pos not in _larkup_protected:
49
+ _larkup_repaired.append(chr(10))
50
+ _larkup_pos += 2
51
+ else:
52
+ _larkup_repaired.append(_larkup_source[_larkup_pos])
53
+ _larkup_pos += 1
54
+ _larkup_candidate = ''.join(_larkup_repaired)
55
+ if _larkup_candidate == _larkup_source:
56
+ raise _larkup_original_error
57
+ _larkup_tree = _larkup_ast.parse(_larkup_candidate, filename='analysis.py', mode='exec')
58
+ _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')]
59
+ _larkup_final_expression = _larkup_expression_indices[-1] if _larkup_expression_indices else -1
60
+ for _larkup_index, _larkup_node in enumerate(_larkup_tree.body):
61
+ if isinstance(_larkup_node, _larkup_ast.Expr):
62
+ if _larkup_index == 0 and isinstance(_larkup_node.value, _larkup_ast.Constant) and isinstance(_larkup_node.value.value, str):
63
+ continue
64
+ _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=[])
65
+ _larkup_ast.fix_missing_locations(_larkup_tree)
66
+ exec(compile(_larkup_tree, 'analysis.py', 'exec'), globals(), globals())`
67
+ .split('\n')
68
+ .map((line) => indentation + line)
69
+ .join('\n');
70
+ }
@@ -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
- exec(compile(base64.b64decode(_larkup_encoded_code), 'analysis.py', 'exec'), globals(), globals())
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.12",
3
+ "version": "0.1.15",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -44,9 +44,9 @@
44
44
  },
45
45
  "optionalDependencies": {
46
46
  "e2b": "^2.39.0",
47
- "@vercel/sandbox": "^3.0.0",
47
+ "@vercel/sandbox": "^4.0.0",
48
48
  "modal": "^0.11.0",
49
- "@daytona/sdk": "^0.226.1",
49
+ "@daytona/sdk": "^2.0.0",
50
50
  "@browserbasehq/sdk": "^2.17.0",
51
51
  "playwright-core": "^1.62.1",
52
52
  "@fly/sprites": "^0.2.0",