codeshield-runtime 0.1.0__tar.gz → 0.1.1__tar.gz

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.
Files changed (20) hide show
  1. {codeshield_runtime-0.1.0 → codeshield_runtime-0.1.1}/PKG-INFO +1 -1
  2. {codeshield_runtime-0.1.0 → codeshield_runtime-0.1.1}/pyproject.toml +1 -1
  3. {codeshield_runtime-0.1.0 → codeshield_runtime-0.1.1}/src/codeshield/environment.py +5 -0
  4. {codeshield_runtime-0.1.0 → codeshield_runtime-0.1.1}/src/codeshield/loop.py +19 -0
  5. {codeshield_runtime-0.1.0 → codeshield_runtime-0.1.1}/tests/test_engine.py +12 -0
  6. {codeshield_runtime-0.1.0 → codeshield_runtime-0.1.1}/.gitignore +0 -0
  7. {codeshield_runtime-0.1.0 → codeshield_runtime-0.1.1}/LICENSE +0 -0
  8. {codeshield_runtime-0.1.0 → codeshield_runtime-0.1.1}/README.md +0 -0
  9. {codeshield_runtime-0.1.0 → codeshield_runtime-0.1.1}/src/codeshield/__init__.py +0 -0
  10. {codeshield_runtime-0.1.0 → codeshield_runtime-0.1.1}/src/codeshield/__main__.py +0 -0
  11. {codeshield_runtime-0.1.0 → codeshield_runtime-0.1.1}/src/codeshield/analyzer.py +0 -0
  12. {codeshield_runtime-0.1.0 → codeshield_runtime-0.1.1}/src/codeshield/classifier.py +0 -0
  13. {codeshield_runtime-0.1.0 → codeshield_runtime-0.1.1}/src/codeshield/cli.py +0 -0
  14. {codeshield_runtime-0.1.0 → codeshield_runtime-0.1.1}/src/codeshield/runner.py +0 -0
  15. {codeshield_runtime-0.1.0 → codeshield_runtime-0.1.1}/src/codeshield/schemas.py +0 -0
  16. {codeshield_runtime-0.1.0 → codeshield_runtime-0.1.1}/src/codeshield/tools.py +0 -0
  17. {codeshield_runtime-0.1.0 → codeshield_runtime-0.1.1}/tests/__init__.py +0 -0
  18. {codeshield_runtime-0.1.0 → codeshield_runtime-0.1.1}/tests/test_cli.py +0 -0
  19. {codeshield_runtime-0.1.0 → codeshield_runtime-0.1.1}/tests/test_coverage.py +0 -0
  20. {codeshield_runtime-0.1.0 → codeshield_runtime-0.1.1}/tests/test_tools.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: codeshield-runtime
3
- Version: 0.1.0
3
+ Version: 0.1.1
4
4
  Summary: A secure, isolated, and self-healing Python code execution engine powered by uv and AST analysis.
5
5
  Project-URL: Homepage, https://github.com/AlgorithmicMind/codeshield
6
6
  Project-URL: Repository, https://github.com/AlgorithmicMind/codeshield
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "codeshield-runtime"
7
- version = "0.1.0"
7
+ version = "0.1.1"
8
8
  description = "A secure, isolated, and self-healing Python code execution engine powered by uv and AST analysis."
9
9
  readme = "README.md"
10
10
  license = { text = "MIT" }
@@ -63,6 +63,11 @@ class SandboxManager:
63
63
  """Return the root sandbox workspace directory."""
64
64
  return self._workspace
65
65
 
66
+ @property
67
+ def workspace_path(self) -> Path:
68
+ """Alias for the root sandbox workspace directory."""
69
+ return self._workspace
70
+
66
71
  @property
67
72
  def venv_path(self) -> Path:
68
73
  """Return the virtual environment directory."""
@@ -224,6 +224,9 @@ class SelfHealingEngine:
224
224
  ) -> tuple[ExecutionResult, ErrorDiagnosis | None]:
225
225
  """Run code through the AST -> sandbox -> heal loop.
226
226
 
227
+ The sandbox is created automatically if ``run`` is called outside a
228
+ ``with`` context manager and is cleaned up once execution finishes.
229
+
227
230
  Args:
228
231
  request: Either a ``CodeExecutionRequest`` or a raw source string.
229
232
  timeout: Optional execution timeout override.
@@ -238,6 +241,22 @@ class SelfHealingEngine:
238
241
  if isinstance(request, str):
239
242
  request = CodeExecutionRequest(code=request)
240
243
 
244
+ auto_created = not self._sandbox.python_executable.exists()
245
+ if auto_created:
246
+ self._sandbox.create()
247
+
248
+ try:
249
+ return self._run_loop(request, timeout)
250
+ finally:
251
+ if auto_created:
252
+ self._sandbox.cleanup()
253
+
254
+ def _run_loop(
255
+ self,
256
+ request: CodeExecutionRequest,
257
+ timeout: float | None,
258
+ ) -> tuple[ExecutionResult, ErrorDiagnosis | None]:
259
+ """Execute the AST -> sandbox -> heal loop assuming the sandbox exists."""
241
260
  diagnosis: ErrorDiagnosis | None = None
242
261
  for attempt in range(1, self._max_iterations + 1):
243
262
  logger.info("Self-healing iteration %d/%d", attempt, self._max_iterations)
@@ -232,3 +232,15 @@ def test_self_healing_engine_fixes_name_error() -> None:
232
232
  assert result.exit_code == 0
233
233
  assert result.stdout.strip() == "4.0"
234
234
  assert diagnosis is None
235
+
236
+
237
+ def test_self_healing_engine_run_without_context_manager() -> None:
238
+ """The engine can be used without a ``with`` block and still auto-manages the sandbox."""
239
+ engine = SelfHealingEngine(use_llm=False)
240
+
241
+ result, diagnosis = engine.run("print('no context manager')")
242
+
243
+ assert result.exit_code == 0
244
+ assert result.stdout.strip() == "no context manager"
245
+ assert diagnosis is None
246
+ assert not engine._sandbox.workspace_path.exists()