Bunnyshell.SDK 0.1.0

dotnet add package Bunnyshell.SDK --version 0.1.0
                    
NuGet\Install-Package Bunnyshell.SDK -Version 0.1.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Bunnyshell.SDK" Version="0.1.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Bunnyshell.SDK" Version="0.1.0" />
                    
Directory.Packages.props
<PackageReference Include="Bunnyshell.SDK" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Bunnyshell.SDK --version 0.1.0
                    
#r "nuget: Bunnyshell.SDK, 0.1.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Bunnyshell.SDK@0.1.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Bunnyshell.SDK&version=0.1.0
                    
Install as a Cake Addin
#tool nuget:?package=Bunnyshell.SDK&version=0.1.0
                    
Install as a Cake Tool

Bunnyshell .NET SDK

Official .NET SDK for Bunnyshell - Secure, isolated cloud sandboxes for code execution, data processing, and AI agents.

What are Bunnyshell Sandboxes?

Bunnyshell Sandboxes are secure, ephemeral virtual machines that let you:

  • Execute untrusted code safely (Python, JavaScript, Shell)
  • Process data in isolated environments
  • Build AI agents with code interpretation capabilities
  • Run commands and manage files programmatically
  • Automate desktop tasks with VNC, screenshots, and keyboard control

Perfect for AI applications, data pipelines, code playgrounds, and automated workflows.

Quick Start

Installation

dotnet add package Bunnyshell.SDK

Basic Usage

using Bunnyshell.SDK;

// Set your API key (get one at https://dashboard.bunnyshell.com)
var sandbox = await Sandbox.CreateAsync(
    template: "code-interpreter",
    apiKey: "your-api-key-here"
);

try
{
    // Execute Python code
    var result = await sandbox.RunCodeAsync(@"
        import numpy as np
        data = [1, 2, 3, 4, 5]
        print(f'Mean: {np.mean(data)}')
    ");
    
    Console.WriteLine(result.Stdout); // Output: Mean: 3.0
}
finally
{
    // Always clean up
    await sandbox.KillAsync();
}

Common Use Cases

1. Code Execution Engine

var sandbox = await Sandbox.CreateAsync(template: "code-interpreter");

// Run Python
var pythonResult = await sandbox.RunCodeAsync("print('Hello from Python!')");

// Run JavaScript
var jsResult = await sandbox.RunCodeAsync(
    "console.log('Hello from Node.js!')", 
    language: "javascript"
);

// Run Shell commands
var shellResult = await sandbox.Commands.RunAsync("ls -la /workspace");

2. File Operations

// Write files
await sandbox.Files.WriteAsync("/workspace/data.txt", "Hello, World!");

// Read files
string content = await sandbox.Files.ReadAsync("/workspace/data.txt");

// Upload from local
await sandbox.Files.UploadAsync("local-file.csv", "/workspace/data.csv");

// Download to local
await sandbox.Files.DownloadAsync("/workspace/results.json", "results.json");

3. Data Processing Pipeline

// Upload raw data
await sandbox.Files.WriteAsync("/workspace/input.csv", csvData);

// Process with Python
await sandbox.RunCodeAsync(@"
    import pandas as pd
    df = pd.read_csv('/workspace/input.csv')
    df['processed'] = df['value'] * 2
    df.to_csv('/workspace/output.csv', index=False)
");

// Download results
await sandbox.Files.DownloadAsync("/workspace/output.csv", "output.csv");

4. AI Agent with Code Interpreter

var sandbox = await Sandbox.CreateAsync(template: "code-interpreter");

// Agent executes code based on user query
var code = GenerateCodeFromUserQuery(userQuery); // Your AI logic
var result = await sandbox.RunCodeAsync(code);

if (result.Success)
{
    Console.WriteLine($"Result: {result.Stdout}");
    
    // Handle plots/charts
    foreach (var output in result.RichOutputs ?? [])
    {
        if (output.Format == "png")
        {
            SaveChart(output.Data); // output.Data is base64 PNG
        }
    }
}

Best Practices

1. Always Clean Up Resources

var sandbox = await Sandbox.CreateAsync(template: "code-interpreter");
try
{
    // Do work
    await sandbox.RunCodeAsync("...");
}
finally
{
    // Always cleanup, even on error
    await sandbox.KillAsync();
}

2. Handle Errors Gracefully

using Bunnyshell.SDK.Exceptions;

try
{
    var result = await sandbox.RunCodeAsync(userCode);
}
catch (CodeExecutionException ex)
{
    Console.WriteLine($"Code error: {ex.Message}");
}
catch (AuthenticationException ex)
{
    Console.WriteLine($"Invalid API key: {ex.Message}");
}
catch (RateLimitException ex)
{
    Console.WriteLine($"Rate limited: {ex.Message}");
    // Implement backoff
}

3. Use Parallel Execution for Performance

// Process multiple tasks in parallel
var tasks = userQueries.Select(query => 
    ProcessQueryAsync(query, sandbox)
);

var results = await Task.WhenAll(tasks);

4. Reuse Sandboxes

// Create once, use multiple times
var sandbox = await Sandbox.CreateAsync(template: "code-interpreter");

try
{
    // State persists between executions (IPython kernel)
    await sandbox.RunCodeAsync("x = 42");
    var result = await sandbox.RunCodeAsync("print(x * 2)");
    // Output: 84
}
finally
{
    await sandbox.KillAsync();
}

Features

Core Capabilities

  • Code Execution - Python, JavaScript, Shell with stdout/stderr capture
  • File Operations - Read, write, upload, download, list directories
  • Command Execution - Run shell commands with full control
  • Environment Variables - Get, set, delete environment configuration
  • Process Management - List and kill processes
  • Desktop Automation - VNC, screenshots, mouse, keyboard (with desktop templates)
  • Async Support - Full async/await for all I/O operations
  • Type Safety - Strong typing with IntelliSense support
  • Error Handling - Typed exceptions for all error cases

Developer Experience

  • 🚀 Zero Dependencies - Only requires .NET 8.0
  • 📝 Full IntelliSense - Complete XML documentation
  • Fast - Lightweight 36KB package
  • 🎯 Fluent API - Intuitive sandbox.Files.ReadAsync() syntax
  • 🔒 Type Safe - Compile-time error checking

Configuration

API Key

Set your API key in one of three ways:

// 1. Pass directly (not recommended for production)
var sandbox = await Sandbox.CreateAsync(
    template: "code-interpreter",
    apiKey: "your-key"
);

// 2. Environment variable (recommended)
Environment.SetEnvironmentVariable("BUNNYSHELL_API_KEY", "your-key");
var sandbox = await Sandbox.CreateAsync(template: "code-interpreter");

// 3. Configuration file (recommended for apps)
var apiKey = Configuration["Bunnyshell:ApiKey"];
var sandbox = await Sandbox.CreateAsync(template: "code-interpreter", apiKey: apiKey);

Custom Resources

var sandbox = await Sandbox.CreateAsync(
    template: "code-interpreter",
    vcpu: 4,              // 4 vCPUs
    memoryMb: 4096,       // 4GB RAM
    diskGb: 20,           // 20GB disk
    timeout: 600          // 10 minute timeout
);

Templates

Available templates:

  • code-interpreter - Python + scientific libraries (NumPy, Pandas, Matplotlib)
  • nodejs - Node.js environment
  • ubuntu-desktop - Full desktop with GUI support

Documentation

Examples Repository

Find complete working examples in the cookbook:

  1. Basic Operations - Sandbox lifecycle and management
  2. Code Execution - Python, JavaScript, Shell execution
  3. File Operations - Complete file management
  4. Commands - Shell command execution
  5. Environment Variables - Configuration management
  6. Process Management - Process control
  7. Desktop Automation - GUI automation
  8. WebSocket Features - Real-time monitoring
  9. Advanced Use Cases - Sandbox pooling, pipelines
  10. Best Practices - Production patterns

Support

License

MIT License - see LICENSE file.


Get your API key: https://dashboard.bunnyshell.com
Star us on GitHub: https://github.com/bunnyshell/sdks

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net8.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.1.0 215 10/23/2025