CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/maven-org-graalvm-polyglot--graalvm-sdk

GraalVM Polyglot API for multi-language runtime environments with host-guest interoperability and security controls.

Pending
Quality

Pending

Does it follow best practices?

Impact

Pending

No eval scenarios have been run

SecuritybySnyk

Pending

The risk profile of this skill

Overview
Eval results
Files

GraalVM Polyglot API

GraalVM Polyglot API enables embedding and interoperating with multiple programming languages within a single runtime environment. It provides comprehensive polyglot execution capabilities, host-guest interoperability, and fine-grained security controls for multi-language applications.

Package Information

  • Package Name: org.graalvm.polyglot
  • Package Type: Maven
  • Language: Java
  • Version: 23.1.5
  • Installation: org.graalvm.polyglot:graalvm-sdk:23.1.5

Core Imports

import org.graalvm.polyglot.Context;
import org.graalvm.polyglot.Engine;
import org.graalvm.polyglot.Value;
import org.graalvm.polyglot.Source;
import org.graalvm.polyglot.HostAccess;
import org.graalvm.polyglot.PolyglotAccess;
import org.graalvm.polyglot.SandboxPolicy;

Basic Usage

// Create context for multiple languages
try (Context context = Context.create("js", "python")) {
    // Evaluate JavaScript code
    Value result = context.eval("js", "6 * 7");
    System.out.println(result.asInt()); // 42
    
    // Host-guest interoperability
    Value bindings = context.getBindings("js");
    bindings.putMember("greeting", "Hello from Java!");
    
    context.eval("js", "console.log(greeting + ' Welcome to polyglot programming!')");
}

Architecture

The GraalVM Polyglot API is organized around these core components:

  • Context: Execution environment for guest languages with isolation and security
  • Engine: Shared runtime that manages multiple contexts and languages
  • Value: Language-agnostic wrapper for all polyglot values and operations
  • Source: Represents source code with language and metadata information
  • Access Policies: Fine-grained control over host access, polyglot interaction, and I/O

Capabilities

Context and Engine Management

Core lifecycle management for polyglot execution environments.

// Context creation and configuration
public static Context create(String... permittedLanguages);
public static Context.Builder newBuilder(String... permittedLanguages);

// Engine creation and sharing
public static Engine create();
public static Engine create(String... permittedLanguages);
public static Engine.Builder newBuilder(String... permittedLanguages);

// Resource management
public void close();
public void close(boolean cancelIfExecuting);

Context and Engine Management

Language Execution and Source Parsing

Evaluation and parsing of source code across different programming languages.

// Source code evaluation
public Value eval(Source source);
public Value eval(String languageId, CharSequence source);

// Source parsing without execution
public Value parse(Source source);
public Value parse(String languageId, CharSequence source);

// Source creation
public static Source create(String language, CharSequence source);
public static Source.Builder newBuilder(String language, CharSequence characters, String name);

Language Execution and Parsing

Value Types and Host-Guest Interoperability

Language-agnostic value operations and seamless data exchange between host and guest languages.

// Type checking and conversion
public boolean isNull();
public boolean isNumber();
public boolean isString();
public String asString();
public int asInt();
public double asDouble();
public <T> T as(Class<T> targetType);

// Container operations
public boolean hasArrayElements();
public Value getArrayElement(long index);
public boolean hasMembers();
public Value getMember(String identifier);

// Function execution
public boolean canExecute();
public Value execute(Object... arguments);

Value Types and Host-Guest Interoperability

Proxy System for Custom Objects

Proxy interfaces enabling host objects to mimic guest language objects with custom behavior.

// Base proxy interface
public interface Proxy {}

// Object-like behavior
public interface ProxyObject extends Proxy {
    Object getMember(String key);
    void putMember(String key, Value value);
    Object getMemberKeys();
}

// Array-like behavior
public interface ProxyArray extends ProxyIterable {
    Object get(long index);
    void set(long index, Value value);
    long getSize();
}

// Function-like behavior
public interface ProxyExecutable extends Proxy {
    Object execute(Value... arguments);
}

Proxy System for Custom Objects

Security and Access Control

Comprehensive security policies for controlling host access, polyglot evaluation, and sandboxing.

// Host access policies
public static final HostAccess EXPLICIT;    // @Export annotation required
public static final HostAccess ALL;         // Full unrestricted access
public static final HostAccess CONSTRAINED; // Limited access for sandboxing
public static final HostAccess UNTRUSTED;   // Strict restrictions

// Polyglot access control
public static final PolyglotAccess ALL;  // Full cross-language access
public static final PolyglotAccess NONE; // No cross-language access

// Sandbox security levels
public enum SandboxPolicy {
    TRUSTED,     // No restrictions
    CONSTRAINED, // Basic restrictions
    ISOLATED,    // Enhanced isolation
    UNTRUSTED    // Maximum restrictions
}

Security and Access Control

I/O and File System Virtualization

Virtual file system abstraction and I/O access control for polyglot contexts.

// I/O access policies
public static final IOAccess ALL;  // Full I/O access
public static final IOAccess NONE; // No I/O access

// File system operations
public interface FileSystem {
    Path parsePath(String path);
    void checkAccess(Path path, Set<? extends AccessMode> modes, LinkOption... linkOptions);
    SeekableByteChannel newByteChannel(Path path, Set<? extends OpenOption> options, FileAttribute<?>... attrs);
    DirectoryStream<Path> newDirectoryStream(Path dir, DirectoryStream.Filter<? super Path> filter);
}

// Byte sequence operations
public interface ByteSequence {
    int length();
    byte byteAt(int index);
    byte[] toByteArray();
}

I/O and File System Virtualization

Execution Monitoring and Resource Management

Performance monitoring, execution tracking, and resource consumption limits.

// Execution monitoring
public final class ExecutionListener implements AutoCloseable {
    public void onEnter(Consumer<ExecutionEvent> listener);
    public void onReturn(Consumer<ExecutionEvent> listener);
    public void attach(Engine engine);
    public void attach(Context context);
}

// Resource limits
public final class ResourceLimits {
    public static ResourceLimits.Builder newBuilder();
}

// Exception handling
public final class PolyglotException extends RuntimeException {
    public boolean isHostException();
    public boolean isGuestException();
    public Value getGuestObject();
    public SourceSection getSourceLocation();
}

Execution Monitoring and Resource Management

Common Types

// Language metadata
public final class Language {
    public String getId();
    public String getName();
    public Set<String> getMimeTypes();
    public boolean isInteractive();
}

// Instrument metadata
public final class Instrument {
    public String getId();
    public String getName();
    public String getVersion();
    public <T> T lookup(Class<T> type);
}

// Source location information
public final class SourceSection {
    public Source getSource();
    public int getStartLine();
    public int getEndLine();
    public int getStartColumn();
    public int getEndColumn();
    public CharSequence getCharacters();
}

// Type-safe generic conversion
public abstract class TypeLiteral<T> {
    public final Type getType();
    public final Class<T> getRawType();
}
Workspace
tessl
Visibility
Public
Created
Last updated
Describes
mavenpkg:maven/org.graalvm.polyglot/graalvm-sdk@23.1.x
Publish Source
CLI
Badge
tessl/maven-org-graalvm-polyglot--graalvm-sdk badge