LogoFreestyle

Run Code

Run code you didn't write

Simple Code Execution

Install the required dependencies

npm i freestyle-sandboxes

Create a Freestyle Client

run.ts
import { FreestyleSandboxes } from "freestyle-sandboxes";
 
const api = new FreestyleSandboxes({
  apiKey: process.env.FREESTYLE_API_KEY!, // make sure to set this
});

Run the code

run.ts
import { FreestyleSandboxes } from "freestyle-sandboxes";
 
const api = new FreestyleSandboxes({
  apiKey: process.env.FREESTYLE_API_KEY!, // make sure to set this
});
 
const code = `export default () => {
// calculate the factorial of every number from 1 to 543 combined
return Array.from({ length: 543 }, (_, i) => i + 1).reduce((acc, cur) => acc * cur, 1);
}`;
 
api.executeScript(code).then((result) => {
  console.log("Result: ", result);
});

Advanced Code Execution

Custom Node Modules

run.ts
import { FreestyleSandboxes } from "freestyle-sandboxes";
 
const api = new FreestyleSandboxes({
  apiKey: process.env.FREESTYLE_API_KEY!, // make sure to set this
});
 
api
  .executeScript(
    `const axios = require('axios');
  const res = await axios.get('https://jsonplaceholder.typicode.com/todos/1');
  return res.data;`,
    {
      nodeModules: {
        axios: "0.21.1",
      },
    }
  )
  .then((result) => {
    console.log("Result: ", result);
  });

This pattern can be used for any node modules, and can be used to connect to any API or service.

Custom Environment Variables

run.ts
import { FreestyleSandboxes } from "freestyle-sandboxes";
 
const api = new FreestyleSandboxes({
  apiKey: process.env.FREESTYLE_API_KEY!, // make sure to set this
});
 
api
  .executeScript(`return process.env.SOME_ENV_VAR;`, {
    envVars: {
      SOME_ENV_VAR: "Hello, World!",
    },
  })
  .then((result) => {
    console.log("Result: ", result);
  });

Environment variables are accessible via the process.env object in the code execution environment.

Running Code with AI

Check out our integrations — we have support for all major AI Agent frameworks. AI models today have gotten incredibly good at writing code, when you give your Agents the ability to run code the scope of problems they can solve. Specifically it makes, data integration and analytical questions. When connecting to an external tool you can build 20 different tools, or you can give your AI the docs and let it figure out how to connect — the ladder is much more adaptable.

Most people who use us start with the prebuilt AI integrations liners, but then move towards a more fine grained approach executing the code themselves with custom definitions.

On this page