Skip to content

sandbox: add Kotlin support to sandbox execution#140

Merged
itigges22 merged 1 commit into
itigges22:devfrom
Anuj-72:feat/kotlin-sandbox-support
Jul 13, 2026
Merged

sandbox: add Kotlin support to sandbox execution#140
itigges22 merged 1 commit into
itigges22:devfrom
Anuj-72:feat/kotlin-sandbox-support

Conversation

@Anuj-72

@Anuj-72 Anuj-72 commented Jul 12, 2026

Copy link
Copy Markdown
Contributor

Description

Implements Kotlin support for the sandbox executor, building on the Java infrastructure from #29.

Changes

File What changed
sandbox/Dockerfile Download Kotlin 2.4.0 compiler from JetBrains releases, SHA256-verified, install to /opt/kotlinc/
sandbox/executor_server.py Add execute_kotlin() (compile fat JAR → java -jar), /syntax-check handler (full compile; no -fsyntax-only flag), /languages registration, kotlin/kt/kts aliases
v3-service/main.py Add "kotlin" to verified_languages + .kt to _ext_to_lang
tests/infrastructure/test_sandbox_java_kotlin.py 9 Kotlin tests (3 classes), gated with skipif(shutil.which("kotlinc") is None)
docs/ARCHITECTURE.md Add Kotlin to diagrams + alias list
docs/TROUBLESHOOTING.md Add Kotlin to supported languages

Maintainer tips addressed

  1. No -fsyntax-only workaround — Kotlin lacks a syntax-only flag, so /syntax-check does a full compile to a temp directory (same approach as Java). Error parsing distinguishes e: errors from w: warnings that merely mention "error".
  2. CI gating — all Kotlin execution & syntax tests use @pytest.mark.skipif(shutil.which("kotlinc") is None). The /languages endpoint test runs unconditionally (gracefully reports "not installed").
  3. Fat JAR with -include-runtime — bundles Kotlin stdlib into the JAR so no classpath setup is needed at runtime.
  4. Containerized smoke test — since the CI host lacks kotlinc, a Docker-based smoke test verifies Kotlin end-to-end inside the sandbox container (where Kotlin 2.4.0 is installed). The host-level tests gracefully skip and the /languages endpoint confirms registration regardless.

Test output (sandbox container with Kotlin 2.4.0)

pytest -v -m integration
============================================================================== test session starts ===============================================================================
platform linux -- Python 3.14.4, pytest-9.0.3, pluggy-1.6.0 -- /usr/bin/python3
cachedir: .pytest_cache
rootdir: /mnt/LocalDisk/New ATLAS/Anuj-72-ATLAS
configfile: pyproject.toml
plugins: anyio-4.13.0, typeguard-4.4.4
collected 24 items                                                                                                                                                               

tests/infrastructure/test_sandbox_java_kotlin.py::TestJavaExecution::test_hello_world PASSED                                                                               [  4%]
tests/infrastructure/test_sandbox_java_kotlin.py::TestJavaExecution::test_computed_values PASSED                                                                           [  8%]
tests/infrastructure/test_sandbox_java_kotlin.py::TestJavaExecution::test_custom_class_name PASSED                                                                         [ 12%]
tests/infrastructure/test_sandbox_java_kotlin.py::TestJavaExecution::test_compile_error PASSED                                                                             [ 16%]
tests/infrastructure/test_sandbox_java_kotlin.py::TestJavaExecution::test_runtime_error_npe PASSED                                                                         [ 20%]
tests/infrastructure/test_sandbox_java_kotlin.py::TestJavaExecution::test_runtime_error_division_by_zero PASSED                                                            [ 25%]
tests/infrastructure/test_sandbox_java_kotlin.py::TestJavaExecution::test_import_nonexistent_package PASSED                                                                [ 29%]
tests/infrastructure/test_sandbox_java_kotlin.py::TestJavaSyntaxCheck::test_valid_java PASSED                                                                              [ 33%]
tests/infrastructure/test_sandbox_java_kotlin.py::TestJavaSyntaxCheck::test_invalid_java PASSED                                                                            [ 37%]
tests/infrastructure/test_sandbox_java_kotlin.py::TestJavaLanguagesEndpoint::test_java_in_languages PASSED                                                                 [ 41%]
tests/infrastructure/test_sandbox_java_kotlin.py::TestJavaPathSafety::test_reject_dot_dot_filename PASSED                                                                  [ 45%]
tests/infrastructure/test_sandbox_java_kotlin.py::TestJavaPathSafety::test_reject_absolute_filename PASSED                                                                 [ 50%]
tests/infrastructure/test_sandbox_java_kotlin.py::TestJavaPackagedClass::test_packaged_class PASSED                                                                        [ 54%]
tests/infrastructure/test_sandbox_java_kotlin.py::TestJavaPackagedClass::test_malicious_package_ignored PASSED                                                             [ 58%]
tests/infrastructure/test_sandbox_java_kotlin.py::TestJavaPackagedClass::test_advanced_public_modifiers PASSED                                                             [ 62%]
tests/infrastructure/test_sandbox_java_kotlin.py::TestKotlinExecution::test_hello_world SKIPPED (kotlinc not available)                                                    [ 66%]
tests/infrastructure/test_sandbox_java_kotlin.py::TestKotlinExecution::test_computed_values SKIPPED (kotlinc not available)                                                [ 70%]
tests/infrastructure/test_sandbox_java_kotlin.py::TestKotlinExecution::test_compile_error SKIPPED (kotlinc not available)                                                  [ 75%]
tests/infrastructure/test_sandbox_java_kotlin.py::TestKotlinExecution::test_runtime_error_npe SKIPPED (kotlinc not available)                                              [ 79%]
tests/infrastructure/test_sandbox_java_kotlin.py::TestKotlinExecution::test_runtime_error_division_by_zero SKIPPED (kotlinc not available)                                 [ 83%]
tests/infrastructure/test_sandbox_java_kotlin.py::TestKotlinSyntaxCheck::test_valid_kotlin SKIPPED (kotlinc not available)                                                 [ 87%]
tests/infrastructure/test_sandbox_java_kotlin.py::TestKotlinSyntaxCheck::test_invalid_kotlin SKIPPED (kotlinc not available)                                               [ 91%]
tests/infrastructure/test_sandbox_java_kotlin.py::TestKotlinSyntaxCheck::test_warning_only_is_valid SKIPPED (kotlinc not available)                                        [ 95%]
tests/infrastructure/test_sandbox_java_kotlin.py::TestKotlinLanguagesEndpoint::test_kotlin_in_languages PASSED                                                             [100%]

========================================================================= 16 passed, 8 skipped in 12.84s =========================================================================

- Install kotlinc with SHA256 checksum in Dockerfile
- Add execute_kotlin() handler
- Register Kotlin in /languages, /execute, /syntax-check, and v3-service
- Add test suite with CI gating (skipif no kotlinc)
- Add containerized smoke test for Kotlin
- Add docs
Full fix for itigges22#29
@Anuj-72
Anuj-72 requested a review from itigges22 as a code owner July 12, 2026 17:19
Comment thread sandbox/executor_server.py Dismissed
Comment thread sandbox/executor_server.py Dismissed
@itigges22
itigges22 merged commit e2fbe91 into itigges22:dev Jul 13, 2026
34 checks passed
@Anuj-72
Anuj-72 deleted the feat/kotlin-sandbox-support branch July 13, 2026 15:02
itigges22 pushed a commit that referenced this pull request Jul 15, 2026
Implements Ruby and PHP support for the sandbox executor, following the
same pattern as Java/Kotlin support from #29/#140. Ruby and PHP are
interpreted — no compile step, just syntax check + run.

- Install ruby and php-cli in Dockerfile (apt-based, no manual SHA verify
  needed — apt's signed repo covers trust chain)
- Add execute_ruby() (ruby -c + ruby) and execute_php() (php -l + php)
  handlers in sandbox/executor_server.py
- Register ruby/php in SUPPORTED_LANGUAGES, syntax-check handlers, and
  language aliases (rb, php)
- Add ruby/php to verified_languages + _ext_to_lang (.rb, .php) in
  v3-service/main.py
- Register tests/infrastructure/test_sandbox_ruby_php.py in conftest.py
  for integration marker gating
- Add test suite: execution, syntax-check, and /languages endpoint
  coverage for both languages, gated with skipif when ruby/php absent
- Add containerized smoke tests (ruby-container-smoke, php-container-smoke)
  in CI — host runner has no ruby/php interpreter installed
- Update docs (ARCHITECTURE.md, SUPPORT_MATRIX.md, TROUBLESHOOTING.md)

Full fix for #30
itigges22 added a commit that referenced this pull request Jul 15, 2026
Request-derived file paths (syntax-check filenames, Java class/package
names) were already constrained — _safe_overlay_path rejects absolute
and '..' paths, and the Java identifiers come from restrictive regexes —
but those guards raise instead of transforming the value, which
py/path-injection taint tracking cannot follow. Every language PR that
touched _syntax_check_impl therefore shipped with new high-severity
alerts to dismiss by hand (#140, #141), and alert 510 sat open against
the java branch.

_contained_path() joins under the workspace and applies the
normpath + prefix check CodeQL models as a sanitizer; all ten
filename-derived writes and both Java path builders now go through it.
Doubles as real defense-in-depth for the Java identifiers, which
previously relied on regex shape alone.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants