agentkernel

package module
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 30, 2026 License: MIT Imports: 10 Imported by: 0

README

agentkernel

Go SDK for agentkernel — run AI coding agents in secure, isolated microVMs.

Install

go get github.com/thrashr888/agentkernel/sdk/golang

Requires Go 1.22+. Zero external dependencies.

Quick Start

package main

import (
	"context"
	"fmt"
	"log"

	agentkernel "github.com/thrashr888/agentkernel/sdk/golang"
)

func main() {
	client := agentkernel.New(nil)

	output, err := client.Run(context.Background(), []string{"echo", "hello"}, nil)
	if err != nil {
		log.Fatal(err)
	}
	fmt.Print(output.Output) // "hello\n"
}

Sandbox Sessions

err := client.WithSandbox(ctx, "test", &agentkernel.CreateSandboxOptions{
	Image: "python:3.12-alpine",
}, func(session *agentkernel.SandboxSession) error {
	session.Run(ctx, []string{"pip", "install", "numpy"})
	output, _ := session.Run(ctx, []string{"python3", "-c", "import numpy; print(numpy.__version__)"})
	fmt.Print(output.Output)
	return nil
})
// sandbox auto-removed

Streaming

ch, err := client.RunStream(ctx, []string{"python3", "script.py"}, nil)
if err != nil {
	log.Fatal(err)
}
for event := range ch {
	if event.Type == "output" {
		fmt.Print(event.Data["content"])
	}
}

Configuration

client := agentkernel.New(&agentkernel.Options{
	BaseURL: "http://localhost:18888", // default
	APIKey:  "sk-...",               // optional
	Timeout: 60 * time.Second,       // default: 30s
})

Or use environment variables:

export AGENTKERNEL_BASE_URL=http://localhost:18888
export AGENTKERNEL_API_KEY=sk-...

License

MIT

Documentation

Overview

Package agentkernel provides a Go client for the agentkernel HTTP API.

Zero external dependencies — uses only the standard library.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsAuthError

func IsAuthError(err error) bool

IsAuthError returns true if the error is an authentication error.

func IsNotFoundError

func IsNotFoundError(err error) bool

IsNotFoundError returns true if the error is a not-found error.

func IsServerError

func IsServerError(err error) bool

IsServerError returns true if the error is a server error.

func IsValidationError

func IsValidationError(err error) bool

IsValidationError returns true if the error is a validation error.

func ParseSSE

func ParseSSE(r io.Reader) <-chan StreamEvent

ParseSSE reads SSE events from r and sends them on the returned channel. The channel is closed when the stream ends or an error occurs. Errors are returned as StreamEvent with Type "error".

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client is the agentkernel API client.

func New

func New(opts *Options) *Client

New creates a new agentkernel client.

Configuration is resolved in order: explicit options > environment variables > defaults.

client := agentkernel.New(nil)                     // defaults + env vars
client := agentkernel.New(&agentkernel.Options{    // explicit
    BaseURL: "http://localhost:9090",
    APIKey:  "sk-...",
})

func (*Client) CreateSandbox

func (c *Client) CreateSandbox(ctx context.Context, name string, opts *CreateSandboxOptions) (*SandboxInfo, error)

CreateSandbox creates a new sandbox.

func (*Client) ExecInSandbox

func (c *Client) ExecInSandbox(ctx context.Context, name string, command []string) (*RunOutput, error)

ExecInSandbox executes a command in an existing sandbox.

func (*Client) GetSandbox

func (c *Client) GetSandbox(ctx context.Context, name string) (*SandboxInfo, error)

GetSandbox returns info about a sandbox.

func (*Client) Health

func (c *Client) Health(ctx context.Context) (string, error)

Health returns "ok" if the server is healthy.

func (*Client) ListSandboxes

func (c *Client) ListSandboxes(ctx context.Context) ([]SandboxInfo, error)

ListSandboxes returns all sandboxes.

func (*Client) RemoveSandbox

func (c *Client) RemoveSandbox(ctx context.Context, name string) error

RemoveSandbox removes a sandbox.

func (*Client) Run

func (c *Client) Run(ctx context.Context, command []string, opts *RunOptions) (*RunOutput, error)

Run executes a command in a temporary sandbox.

func (*Client) RunStream

func (c *Client) RunStream(ctx context.Context, command []string, opts *RunOptions) (<-chan StreamEvent, error)

RunStream executes a command with SSE streaming output. Returns a channel of StreamEvent. The channel is closed when the stream ends.

func (*Client) WithSandbox

func (c *Client) WithSandbox(ctx context.Context, name string, opts *CreateSandboxOptions, fn func(session *SandboxSession) error) error

WithSandbox creates a sandbox, passes a SandboxSession to fn, and removes the sandbox when fn returns — even if fn returns an error.

type CreateSandboxOptions

type CreateSandboxOptions struct {
	Image string `json:"image,omitempty"`
}

CreateSandboxOptions configures sandbox creation.

type Error

type Error struct {
	StatusCode int
	Message    string
}

Error represents an agentkernel API error.

func (*Error) Error

func (e *Error) Error() string

type Options

type Options struct {
	// BaseURL is the agentkernel server URL. Default: http://localhost:18888
	BaseURL string

	// APIKey is the optional API key for authentication.
	APIKey string

	// Timeout is the HTTP request timeout. Default: 30s.
	Timeout time.Duration

	// HTTPClient overrides the default http.Client. Useful for testing.
	HTTPClient *http.Client
}

Options configures the agentkernel client.

type RunOptions

type RunOptions struct {
	Image   string          `json:"image,omitempty"`
	Profile SecurityProfile `json:"profile,omitempty"`
	Fast    *bool           `json:"fast,omitempty"`
}

RunOptions configures a run command.

type RunOutput

type RunOutput struct {
	Output string `json:"output"`
}

RunOutput is the result of a run or exec command.

type SandboxInfo

type SandboxInfo struct {
	Name    string `json:"name"`
	Status  string `json:"status"`
	Backend string `json:"backend,omitempty"`
}

SandboxInfo describes a sandbox.

type SandboxSession

type SandboxSession struct {
	// contains filtered or unexported fields
}

SandboxSession provides a handle to run commands in an existing sandbox. Used within the Client.WithSandbox callback.

func (*SandboxSession) Info

func (s *SandboxSession) Info(ctx context.Context) (*SandboxInfo, error)

Info returns the sandbox's current info.

func (*SandboxSession) Name

func (s *SandboxSession) Name() string

Name returns the sandbox name.

func (*SandboxSession) Run

func (s *SandboxSession) Run(ctx context.Context, command []string) (*RunOutput, error)

Run executes a command in the sandbox.

type SecurityProfile

type SecurityProfile string

SecurityProfile controls sandbox permissions.

const (
	ProfilePermissive  SecurityProfile = "permissive"
	ProfileModerate    SecurityProfile = "moderate"
	ProfileRestrictive SecurityProfile = "restrictive"
)

type StreamEvent

type StreamEvent struct {
	Type string                 `json:"type"`
	Data map[string]interface{} `json:"data,omitempty"`
}

StreamEvent is a server-sent event from a streaming run.

Directories

Path Synopsis
examples
quickstart command
sandbox command

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL