Skip to main content

YepCode Run - A powerful serverless runtime and SDK for executing code in secure sandboxes

Project description

YepCode Run SDK Preview

PyPI Version PyPI Downloads GitHub Workflow Status

What is YepCode Run?

YepCode Run is a powerful serverless runtime that enables secure code execution in isolated sandboxes. With our comprehensive SDK and platform, you can effortlessly build, manage, and monitor your script executions. Get started quickly using our JavaScript SDK or Python SDK.

Powered by YepCode Cloud, our enterprise-grade platform delivers seamless script execution capabilities for AI agents, data processing pipelines, API integrations, and automation workflows. Focus on your code while we handle the infrastructure.

Quick start

1. Installation

pip install yepcode-run

2. Get your YepCode API token

  1. Sign up to YepCode Cloud

  2. Get your API token from your workspace under: Settings > API credentials

  3. Use your API token securely in one of these ways:

    # Option 1: Set as environment variable (Recommended)
    # .env file
    YEPCODE_API_TOKEN=your_token_here
    
    # Option 2: Provide directly to the constructor (Not recommended for production)
    runner = YepCodeRun(YepCodeApiConfig(api_token='your_token_here'))
    

3. Execute your code

from yepcode_run import YepCodeRun, YepCodeApiConfig

runner = YepCodeRun(
    YepCodeApiConfig(api_token='your-api-token')
)

# Execute code with full options
execution = runner.run(
    """def main():
    message = "Hello, YepCode!"
    print(message)
    return {"message": message}""",
    {
        "language": "python",  # Optional - auto-detected if not specified
        "onLog": lambda log: print(f"{log.timestamp} {log.level}: {log.message}"),
        "onFinish": lambda return_value: print("Finished:", return_value),
        "onError": lambda error: print("Error:", error)
    }
)

# Wait for execution to complete
execution.wait_for_done()

# Retrieve an existing execution
existing_execution = runner.get_execution('execution-id')

4. Manage Environment Variables

You may use environment variables in your code with process.env (JavaScript) or os.getenv (Python), and you may manage this environment variables in the YepCode platform (docs here), or using this YepCodeEnv class:

from yepcode_run import YepCodeEnv, YepCodeApiConfig

env = YepCodeEnv(
    YepCodeApiConfig(api_token='your-api-token')
)

# Set environment variables
env.set_env_var('API_KEY', 'secret-value')           # Sensitive by default
env.set_env_var('DEBUG', 'true', False)             # Non-sensitive variable

# Get all environment variables
variables = env.get_env_vars()
# Returns: [TeamVariable(key='API_KEY', value='secret-value'), TeamVariable(key='DEBUG', value='true')]

# Delete an environment variable
env.del_env_var('API_KEY')

5. Direct API access

You can also directly access the full YepCode API using the YepCodeApi class:

from yepcode_run import YepCodeApi, YepCodeApiConfig

api = YepCodeApi(
  YepCodeApiConfig(api_token='your-api-token')
)

# Get all processes
processes = api.get_processes()

6. YepCode Storage

You can manage files in your YepCode workspace using the YepCodeStorage class. This allows you to upload, list, download, and delete files easily.

from yepcode_run import YepCodeStorage, YepCodeApiConfig

storage = YepCodeStorage(
    YepCodeApiConfig(api_token='your-api-token')
)

# Upload a file
with open('myfile.txt', 'rb') as f:
    obj = storage.upload('myfile.txt', f)
    print('Uploaded:', obj.name, obj.size, obj.link)

# List all storage objects
objects = storage.list()
for obj in objects:
    print(obj.name, obj.size, obj.link)

# Create a signed URL (default expiry: 1 hour)
signed = storage.create_signed_url('myfile.txt')
print('Signed URL:', signed.url)
print('Expires at:', signed.expires_at)

# Create a signed URL with custom expiry (in seconds)
short_lived = storage.create_signed_url('myfile.txt', expires_in_seconds=300)

# Download a file
content = storage.download('myfile.txt')
with open('downloaded.txt', 'wb') as f:
    f.write(content)

# Delete a file
storage.delete('myfile.txt')

Prompt to use if you are asking LLM to write code

You can use the following prompt to ask LLM to write code that the YepCode Run SDK can execute.

You should replace the {{task}} and {{envVars}} placeholders with the actual task and environment variables names already set in your YepCode workspace.

Acts as a coding agent to help the user to achieve the described task generating a standalone script in either JavaScript or Python. Do not write any explainations, just write the code.

The task to solve is:

=====
{{task}}
=====

* We support JavaScript (NodeJS v22) or Python (v3.13).
* You may use the following environment variables already set in the execution context: {{envVars}}
* Use external dependencies freely from NPM or PyPI. You should import them as usually.
  * If package name is different from the import sentence, add an anotation for us to detect them (\`// @add-package package_name\` (javascript) or \`# @add-package package_name\` (python)).
  * When possible, use binary packages to avoid compilation issues.
* Include debugging logs (\`console.log()\` in javascript or \`print()\` in python) if necessary for execution tracking and error debugging.
* Do not catch errors, let them fail the execution.
* Follow the required script structure based on the chosen language:

---------------------------------
JavaScript
----------
// @add-package package_name_1
const package_name_1 = require("package_name_1");
// @add-package package_name_2
const package_name_2 = require("package_name_2");

async function main() {
    // The generated code should go here
    return {"success": true, "data": result}
}

module.exports = { main }
---------------------------------

---------------------------------
Python
------
# @add-package package_name_1
import package_name_1
# @add-package package_name_2
from package_name_2.module import Module

def main():
    # The generated code should go here
    return {"success": True, "data": result}

---------------------------------

Important: The response should only contain the script to be executed by `python` or `node` and follow the exact structure above. Do not include any explanations neither enclosing annotations.

SDK API Reference

YepCodeRun

The main class for executing code in YepCode's runtime environment.

Methods

run(code: str, options: Optional[Dict[str, Any]] = None) -> Execution

Executes code in YepCode's runtime environment.

Parameters:

  • code: Source code to execute (string)

  • options: Execution options (optional)

    {
        "language": Optional[str],        # 'javascript' or 'python'
        "onLog": Optional[Callable],      # Log event handler
        "onFinish": Optional[Callable],   # Success completion handler
        "onError": Optional[Callable],    # Error handler
        "removeOnDone": Optional[bool],   # Auto-cleanup after execution
        "parameters": Optional[Any],      # Execution parameters
        "manifest": Optional[Dict],       # Custom process manifest
        "timeout": Optional[int]          # Execution timeout in ms
    }
    

Returns: Execution

get_execution(execution_id: str) -> Execution

Retrieves an existing execution by ID.

Parameters:

  • execution_id: Unique identifier for the execution

Returns: Execution

Execution class

Represents a code execution instance.

Properties:

class Execution:
    id: str                    # Unique identifier
    logs: List[Log]                      # Array of execution logs
    process_id: Optional[str]            # ID of the associated process
    status: Optional[ExecutionStatus]    # Current execution status
    return_value: Any                    # Execution result
    error: Optional[str]                 # Error message
    timeline: Optional[List[TimelineEvent]]  # Execution timeline events
    parameters: Any                      # Execution input parameters
    comment: Optional[str]               # Execution comment

Methods:

is_done() -> bool

Returns whether the execution has completed.

Returns: bool

wait_for_done() -> None

Waits for the execution to complete.

Returns: None

kill() -> None

Terminates the execution.

Returns: None

rerun() -> Execution

Creates a new execution with the same configuration.

Returns: Execution

YepCodeEnv

Manages environment variables for your YepCode workspace.

Methods

get_env_vars() -> List[TeamVariable]

Returns all environment variables.

Returns: List[TeamVariable]

class TeamVariable:
    key: str
    value: str
    is_sensitive: bool
set_env_var(key: str, value: str, is_sensitive: bool = True) -> None

Sets an environment variable.

Parameters:

  • key: Variable name
  • value: Variable value
  • is_sensitive: Whether the variable contains sensitive data (defaults to true)

Returns: None

del_env_var(key: str) -> None

Deletes an environment variable.

Parameters:

  • key: Variable name to delete

Returns: None

YepCodeApi

Provides direct access to the YepCode API.

Methods

get_processes() -> List[Process]

Returns all available processes.

Returns: List[Process]

class Process:
    id: str
    name: str
    description: Optional[str]
    created_at: str

YepCodeStorage

The main class for managing files in YepCode's cloud storage.

Methods

upload(name: str, file: bytes) -> StorageObject

Uploads a file to YepCode storage.

Parameters:

  • name: Name of the file in storage
  • file: File content as bytes or a file-like object

Returns: StorageObject

download(name: str) -> bytes

Downloads a file from YepCode storage.

Parameters:

  • name: Name of the file to download

Returns: File content as bytes

delete(name: str) -> None

Deletes a file from YepCode storage.

Parameters:

  • name: Name of the file to delete

Returns: None

list() -> List[StorageObject]

Lists all files in YepCode storage.

Returns: List of StorageObject

create_signed_url(name: str, expires_in_seconds: Optional[int] = None) -> SignedUrl

Creates a temporary signed URL for a storage object.

Parameters:

  • name: Name of the file in storage
  • expires_in_seconds: Expiration time for the URL in seconds (optional)

Returns: SignedUrl

Types

class StorageObject:
    name: str           # File name
    size: int           # File size in bytes
    md5_hash: str       # MD5 hash of the file
    content_type: str   # MIME type
    created_at: str     # Creation timestamp (ISO8601)
    updated_at: str     # Last update timestamp (ISO8601)
    link: str           # Download link

class CreateStorageObjectInput:
    name: str           # File name
    file: Any           # File content (bytes or file-like)

class CreateSignedUrlInput:
    path: str                           # File path in storage
    expires_in_seconds: Optional[int]   # Expiration time in seconds

class SignedUrl:
    url: str          # Temporary signed URL
    path: str         # File path in storage
    expires_at: str   # Expiration timestamp (ISO8601)

License

This project is licensed under the MIT License - see the LICENSE file for details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

yepcode_run-1.9.0.tar.gz (20.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

yepcode_run-1.9.0-py3-none-any.whl (21.5 kB view details)

Uploaded Python 3

File details

Details for the file yepcode_run-1.9.0.tar.gz.

File metadata

  • Download URL: yepcode_run-1.9.0.tar.gz
  • Upload date:
  • Size: 20.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.3.4 CPython/3.12.13 Linux/6.17.0-1011-azure

File hashes

Hashes for yepcode_run-1.9.0.tar.gz
Algorithm Hash digest
SHA256 8b982ddfbfb8556a888663516ca90bfbdc51dcd2d144167337fd2ac45c885dea
MD5 63f271df6cafb594439790530634440c
BLAKE2b-256 c699674615506aee8fa540e32535eab1d3119dbadc8a8795882e13ecd7c215f5

See more details on using hashes here.

File details

Details for the file yepcode_run-1.9.0-py3-none-any.whl.

File metadata

  • Download URL: yepcode_run-1.9.0-py3-none-any.whl
  • Upload date:
  • Size: 21.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.3.4 CPython/3.12.13 Linux/6.17.0-1011-azure

File hashes

Hashes for yepcode_run-1.9.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f25cba220f59cff35393b57b3b719f8908bfa47f78353241d1eb52a892fa0daf
MD5 94383cfa0208cc1d839f10a33a39cf8b
BLAKE2b-256 f68ac2e64d959fedd4b07ef8e548ca090139e001f5f3e7c4f3d3fa5b9056c427

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page