Interfaze

logo

Beta

pricing

docs

blog

sign in

Get Started

Introduction

Examples

Vision

Concepts

Resources

Projects

Integrations

Code Sandboxing and Execution

copy markdown

Run code in sandboxes for Python and TypeScript in isolated secure environments with sub-second spin up times.

  • Python & TypeScript support
  • <100ms spin up times
  • Isolated environments close to the GPUs
  • Massive parallelism with thousands of concurrent executions

Basic example

OpenAI SDK

Vercel AI SDK

LangChain SDK

import { z } from "zod";
import { zodResponseFormat } from "openai/helpers/zod";

const FactorialSchema = z.object({
	fractional: z.number(),
});

const response = await interfaze.chat.completions.create({
	model: "interfaze-beta",
	messages: [
		{
			role: "user",
			content: "What is the factorial of 5?",
		},
	],
	response_format: zodResponseFormat(FactorialSchema, "factorial_schema"),
});

console.log(response.choices[0].message.content);

//@ts-expect-error precontext is not typed
const precontext = response.precontext;
console.log("Sandbox Results:", precontext?.[0]?.result);

JSON output

{
  "object": {
    "fractional": 120
  },
  "response": {
    "id": "interfaze-1775193886199",
    "modelId": "interfaze-beta",
    "body": {
      "id": "interfaze-1775193886199",
      "object": "chat.completion",
      "model": "interfaze-beta",
      "usage": {
        "prompt_tokens": 2236,
        "completion_tokens": 21,
        "total_tokens": 2257
      },
      "precontext": [
        {
          "name": "code_execute",
          "result": {
            "code_script": "# Calculate factorial of 5 and print\nimport math\nprint(math.factorial(5))",
            "language": "python",
            "output": "120\n",
            "is_action_tool": true
          }
        }
      ]
    }
  },
  "finishReason": "stop",
  "usage": {
    "inputTokens": 2236,
    "outputTokens": 21,
    "totalTokens": 2257
  }
}

precontext contains the code generated and executed by the model to achieve the final response.

Counting tasks

OpenAI SDK

Vercel AI SDK

LangChain SDK

import { z } from "zod";
import { zodResponseFormat } from "openai/helpers/zod";

const CountingSchema = z.object({
	answer: z.number(),
});

const response = await interfaze.chat.completions.create({
	model: "interfaze-beta",
	messages: [
		{
			role: "user",
			content: "How many r's are there in strawberry?",
		},
	],
	response_format: zodResponseFormat(CountingSchema, "counting_schema"),
});

console.log(response.choices[0].message.content);

//@ts-expect-error precontext is not typed
const precontext = response.precontext;
console.log("Sandbox Results:", precontext?.[0]?.result);

JSON output

{
  "object": {
    "answer": 3
  },
  "response": {
    "id": "interfaze-1775195660480",
    "modelId": "interfaze-beta",
    "body": {
      "id": "interfaze-1775195660480",
      "object": "chat.completion",
      "model": "interfaze-beta",
      "usage": {
        "prompt_tokens": 2278,
        "completion_tokens": 21,
        "total_tokens": 2299
      },
      "precontext": [
        {
          "name": "code_execute",
          "result": {
            "code_script": "print('strawberry'.count('r'))",
            "language": "python",
            "output": "3\n",
            "is_action_tool": true
          }
        }
      ]
    }
  },
  "finishReason": "stop",
  "usage": {
    "inputTokens": 2278,
    "outputTokens": 21,
    "totalTokens": 2299
  }
}

Graphical Code Generation

OpenAI SDK

Vercel AI SDK

LangChain SDK

const response = await interfaze.chat.completions.create({
	model: "interfaze-beta",
	messages: [
		{
			role: "user",
			content: "Create me a bouncing ball animation in python",
		},
	],
});

console.log(response.choices[0].message.content);

/*
Response -

import sys
import random
import pygame

def main():
    # Initialize Pygame
    pygame.init()
    WIDTH, HEIGHT = 800, 600
    screen = pygame.display.set_mode((WIDTH, HEIGHT))
    pygame.display.set_caption("Bouncing Ball")

    # Colors
    BG = (18, 18, 18)
    BALL_COLOR = (52, 152, 219)

    # Ball properties
    radius = 25
    x = WIDTH // 2
    y = HEIGHT // 2
    # Random initial velocity
    vx = random.choice([-5, -4, -3, 3, 4, 5])
    vy = random.choice([-5, -4, -3, 3, 4, 5])

    clock = pygame.time.Clock()
    FPS = 60

    running = True
    while running:
        # Event handling
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                running = False

        # Update position
        x += vx
        y += vy

        # Bounce on walls
        if x - radius <= 0:
            x = radius
            vx = -vx
        elif x + radius >= WIDTH:
            x = WIDTH - radius
            vx = -vx

        if y - radius <= 0:
            y = radius
            vy = -vy
        elif y + radius >= HEIGHT:
            y = HEIGHT - radius
            vy = -vy

        # Draw
        screen.fill(BG)
        pygame.draw.circle(screen, BALL_COLOR, (int(x), int(y)), radius)
        pygame.display.flip()

        # Cap the frame rate
        clock.tick(FPS)

    pygame.quit()
    sys.exit()

if __name__ == "__main__":
    main()
*/

//@ts-expect-error precontext is not typed
const precontext = response.precontext;
console.log("Sandbox Results:", precontext?.[0]?.result);